• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Docker Environment<a name="EN-US_TOPIC_0000001055701144"></a>
2
3-   [Introduction](#section107932281315)
4-   [Preparations](#section7337134183512)
5-   [Standalone Docker Environment](#section2858536103611)
6    -   [Setting Up the Docker Environment for Mini-System Devices \(reference memory ≥ 128 KB\) and Small-System Devices \(reference memory ≥ 1 MB\)](#section319412277287)
7    -   [Building for Mini-System Devices \(reference memory ≥ 128 KB\) and Small-System Devices \(reference memory ≥ 1 MB\)](#section631485163615)
8    -   [Setting Up the Docker Environment for Standard-System Devices \(reference memory ≥ 128 MB\)](#section13585262391)
9    -   [Building for Standard-System Devices \(reference memory ≥ 128 MB\)](#section193711513406)
10
11-   [HPM-based Docker Environment](#section485713518337)
12    -   [Setting Up the Docker Environment](#section3295842510)
13    -   [Obtaining and Building Source Code](#section69141039143518)
14
15
16## Introduction<a name="section107932281315"></a>
17
18OpenHarmony provides the following two types of Docker environments for you to quickly get the development environment ready:
19
20-   Standalone Docker environment: applicable when using Ubuntu or Windows to build a distribution
21-   HPM-based Docker environment: applicable when using the HarmonyOS Package Manager \(HPM\) to build a distribution
22
23**Table  1**  Docker image
24
25<a name="table11986917191214"></a>
26<table><thead align="left"><tr id="row149861417121215"><th class="cellrowborder" valign="top" width="15.831583158315832%" id="mcps1.2.6.1.1"><p id="p798611714124"><a name="p798611714124"></a><a name="p798611714124"></a>Docker Environment</p>
27</th>
28<th class="cellrowborder" valign="top" width="13.97139713971397%" id="mcps1.2.6.1.2"><p id="p1698661751219"><a name="p1698661751219"></a><a name="p1698661751219"></a>System Type</p>
29</th>
30<th class="cellrowborder" valign="top" width="18.61186118611861%" id="mcps1.2.6.1.3"><p id="p1798671761217"><a name="p1798671761217"></a><a name="p1798671761217"></a>Operating Platform</p>
31</th>
32<th class="cellrowborder" valign="top" width="35.8935893589359%" id="mcps1.2.6.1.4"><p id="p20526205414295"><a name="p20526205414295"></a><a name="p20526205414295"></a>Docker Image Repository</p>
33</th>
34<th class="cellrowborder" valign="top" width="15.69156915691569%" id="mcps1.2.6.1.5"><p id="p1833001309"><a name="p1833001309"></a><a name="p1833001309"></a>Tag</p>
35</th>
36</tr>
37</thead>
38<tbody><tr id="row1798661751216"><td class="cellrowborder" rowspan="2" align="center" valign="top" width="15.831583158315832%" headers="mcps1.2.6.1.1 "><p id="p1898631791213"><a name="p1898631791213"></a><a name="p1898631791213"></a>Standalone Docker environment</p>
39</td>
40<td class="cellrowborder" valign="top" width="13.97139713971397%" headers="mcps1.2.6.1.2 "><p id="p1598617177128"><a name="p1598617177128"></a><a name="p1598617177128"></a>Mini and small systems</p>
41</td>
42<td class="cellrowborder" valign="top" width="18.61186118611861%" headers="mcps1.2.6.1.3 "><p id="p898614178122"><a name="p898614178122"></a><a name="p898614178122"></a>Ubuntu or Windows</p>
43</td>
44<td class="cellrowborder" valign="top" width="35.8935893589359%" headers="mcps1.2.6.1.4 "><p id="p12667431305"><a name="p12667431305"></a><a name="p12667431305"></a>swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker</p>
45</td>
46<td class="cellrowborder" valign="top" width="15.69156915691569%" headers="mcps1.2.6.1.5 "><p id="p143320173017"><a name="p143320173017"></a><a name="p143320173017"></a>0.0.5</p>
47</td>
48</tr>
49<tr id="row998612174129"><td class="cellrowborder" valign="top" headers="mcps1.2.6.1.1 "><p id="p1998617172126"><a name="p1998617172126"></a><a name="p1998617172126"></a>Standard system</p>
50</td>
51<td class="cellrowborder" valign="top" headers="mcps1.2.6.1.2 "><p id="p1598641741215"><a name="p1598641741215"></a><a name="p1598641741215"></a>Ubuntu</p>
52</td>
53<td class="cellrowborder" valign="top" headers="mcps1.2.6.1.3 "><p id="p552616549297"><a name="p552616549297"></a><a name="p552616549297"></a>swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker-standard</p>
54</td>
55<td class="cellrowborder" valign="top" headers="mcps1.2.6.1.4 "><p id="p1633303300"><a name="p1633303300"></a><a name="p1633303300"></a>0.0.4</p>
56</td>
57</tr>
58<tr id="row5986201731214"><td class="cellrowborder" align="center" valign="top" width="15.831583158315832%" headers="mcps1.2.6.1.1 "><p id="p136981216143"><a name="p136981216143"></a><a name="p136981216143"></a>HPM-based Docker environment</p>
59</td>
60<td class="cellrowborder" valign="top" width="13.97139713971397%" headers="mcps1.2.6.1.2 "><p id="p969831161416"><a name="p969831161416"></a><a name="p969831161416"></a>Mini and small systems</p>
61</td>
62<td class="cellrowborder" valign="top" width="18.61186118611861%" headers="mcps1.2.6.1.3 "><p id="p18821161052214"><a name="p18821161052214"></a><a name="p18821161052214"></a>Ubuntu or Windows</p>
63</td>
64<td class="cellrowborder" valign="top" width="35.8935893589359%" headers="mcps1.2.6.1.4 "><p id="p1652616548294"><a name="p1652616548294"></a><a name="p1652616548294"></a>swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker</p>
65</td>
66<td class="cellrowborder" valign="top" width="15.69156915691569%" headers="mcps1.2.6.1.5 "><p id="p1433130173010"><a name="p1433130173010"></a><a name="p1433130173010"></a>0.0.3</p>
67</td>
68</tr>
69</tbody>
70</table>
71
72
73## Preparations<a name="section7337134183512"></a>
74
75Before using the Docker environment, perform the following operations:
76
771.  Install Docker. For details, see  [Install Docker Engine](https://docs.docker.com/engine/install/).
782.  Obtain the OpenHarmony source code. For details, see  [Source Code Acquisition](sourcecode-acquire.md).
79
80    >![](../public_sys-resources/icon-note.gif) **NOTE:**
81    >You do not need to obtain the source code for the HPM-based Docker environment.
82
83
84## Standalone Docker Environment<a name="section2858536103611"></a>
85
86The Docker image of OpenHarmony is hosted on  [HUAWEI CLOUD SWR](https://console.huaweicloud.com/swr/?region=cn-south-1&locale=en-us#/app/warehouse/warehouseMangeDetail/goldensir/openharmony-docker/openharmony-docker?type=ownImage). Using the Docker image will help simplify environment configurations needed for the building. The following describes the detailed procedure.
87
88### Setting Up the Docker Environment for Mini-System Devices \(reference memory ≥ 128 KB\) and Small-System Devices \(reference memory ≥ 1 MB\)<a name="section319412277287"></a>
89
90**Method 1: Obtaining the Docker image from HUAWEI CLOUD SWR**
91
921.  Obtain the Docker image.
93
94    ```
95    docker pull swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:0.0.5
96    ```
97
982.  Go to the root directory of OpenHarmony code and run the following command to access the Docker build environment:
99
100    Run the following command in Ubuntu:
101
102    ```
103    docker run -it -v $(pwd):/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:0.0.5
104    ```
105
106    Run the following command in Windows \(assuming that the source code directory is  **D:\\OpenHarmony**\):
107
108    ```
109    docker run -it -v D:\OpenHarmony:/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:0.0.5
110    ```
111
112
113**Method 2: Using the Dockerfile to Build a Local Docker Image**
114
1151.  Obtain the Dockerfile script for a local Docker image.
116
117    ```
118    git clone https://gitee.com/openharmony/docs.git
119    ```
120
1212.  Go to the directory of the Dockerfile code and run the following command to build the Docker image:
122
123    ```
124    cd docs/docker
125    ./build.sh
126    ```
127
1283.  Go to the root directory of OpenHarmony code and run the following command to access the Docker build environment:
129
130    Run the following command in Ubuntu:
131
132    ```
133    docker run -it -v $(pwd):/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:0.0.5
134    ```
135
136    Run the following command in Windows \(assuming that the source code directory is  **D:\\OpenHarmony**\):
137
138    ```
139    docker run -it -v D:\OpenHarmony:/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:0.0.5
140    ```
141
142
143### Building for Mini-System Devices \(reference memory ≥ 128 KB\) and Small-System Devices \(reference memory ≥ 1 MB\)<a name="section631485163615"></a>
144
145The following uses the Hi3516 platform as an example to describe the build procedure.
146
147Set the build path to the current path.
148
149```
150hb set
151 .
152```
153
154**Figure  1**  Setting page<a name="fig7947145854013"></a>
155![](figure/setting-page.png "setting-page")
156
157>![](../public_sys-resources/icon-note.gif) **NOTE:**
158>The mapping between the development board and the building GUI:
159>-   Hi3861: wifiiot\_hispark\_pegasus@hisilicon
160>-   Hi3516: ipcamera\_hispark\_taurus@hisilicon
161>-   Hi3518: ipcamera\_hispark\_aries@hisilicon
162
1631.  Select  **ipcamera\_hispark\_taurus@hisilicon**  and press  **Enter**.
1642.  Start building.
165
166    ```
167    hb build -f
168    ```
169
1703.  View the build result.
171
172    The files will be generated in the  **out/hispark\_taurus/ipcamera\_hispark\_taurus**  directory.
173
174
175### Setting Up the Docker Environment for Standard-System Devices \(reference memory ≥ 128 MB\)<a name="section13585262391"></a>
176
177**Method 1: Obtaining the Docker image from HUAWEI CLOUD SWR**
178
1791.  Obtain the Docker image.
180
181    ```
182    docker pull swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker-standard:0.0.4
183    ```
184
1852.  Go to the root directory of OpenHarmony code and run the following command to access the Docker build environment:
186
187    ```
188    docker run -it -v $(pwd):/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker-standard:0.0.3
189    ```
190
191
192**Method 2: Using the Dockerfile to Build a Local Docker Image**
193
1941.  Obtain the Dockerfile script for a local Docker image.
195
196    ```
197    git clone https://gitee.com/openharmony/docs.git
198    ```
199
2002.  Go to the directory of the Dockerfile code and run the following command to build the Docker image:
201
202    ```
203    cd docs/docker/standard
204    ./build.sh
205    ```
206
2073.  Go to the root directory of OpenHarmony code and run the following command to access the Docker build environment:
208
209    ```
210    docker run -it -v $(pwd):/home/openharmony openharmony-docker-standard:0.0.3
211    ```
212
213
214### Building for Standard-System Devices \(reference memory ≥ 128 MB\)<a name="section193711513406"></a>
215
216Run the following script to start building for standard-system devices \(reference memory ≥ 128 MB\).
217
218```
219./build.sh --product-name {product_name}
220```
221
222**product\_name**  indicates the platform supported by the current distribution, for example, Hi3516D V300.
223
224Files generated during building are stored in the  **out/ohos-arm-release/**  directory, and the generated image is stored in the  **out/ohos-arm-release/packages/phone/images/**  directory.
225
226
227>![](../public_sys-resources/icon-note.gif) **NOTE:**
228>You can exit Docker by simply running the  **exit**  command.
229
230## HPM-based Docker Environment<a name="section485713518337"></a>
231
232**docker\_dist**  is a template component in the  [HPM](https://hpm.harmonyos.com/#/en/home)  system. It helps to quickly initialize an HPM project and use the Docker image to quickly build a distribution of OpenHarmony, greatly simplifying environment configurations needed for building. After configuring the Ubuntu and  [hpm-cli](../bundles/bundles-guide-prepare.md)  development environments, perform the following steps to access the Docker environment:
233
234### Setting Up the Docker Environment<a name="section3295842510"></a>
235
2361.  Initialize the installation template by running the following command in any of the working directories:
237
238    ```
239    hpm init -t @ohos/docker_dist
240    ```
241
2422.  Modify the  **publishAs**  field.
243
244    The obtained bundle is of the template type. Open the  **bundle.json**  file in the current directory and change the value of  **publishAs**  from  **template**  to  **distribution**  as needed.
245
246
247### Obtaining and Building Source Code<a name="section69141039143518"></a>
248
249Start building. Docker can be automatically installed only in Ubuntu. If you are using any other operating system, manually install Docker before pulling the image.
250
251-   **Automatically Installing Docker \(Ubuntu\)**
252
253    Running the following command will automatically install Docker, pull the Docker image, and start the pulling and building of the corresponding solution in the container.
254
255    **Method 1:**
256
257    Add a parameter to specify the solution. For example:
258
259    ```
260    hpm run docker solution={product}
261    ```
262
263    **\{product\}**  indicates the solution, for example,  **@ohos/hispark\_taurus**,  **@ohos/hispark\_aries**, and  **@ohos/hispark\_pegasus**.
264
265    **Method 2:**
266
267    Set an environment variable to specify the solution, and then run the build command.
268
269    1.  Select the desired solution.
270
271        ```
272        export solution={product}
273        ```
274
275        **\{product\}**  indicates the solution, for example,  **@ohos/hispark\_taurus**,  **@ohos/hispark\_aries**, and  **@ohos/hispark\_pegasus**.
276
277    2.  Obtain and build the source code.
278
279        ```
280        hpm run docker
281        ```
282
283    This example uses the  **@ohos/hispark\_taurus**  solution for illustration. If the execution is successful, the output is as follows:
284
285    ```
286    ...
287    ohos ipcamera_hispark_taurus build success!
288    @ohos/hispark_taurus: distribution building completed.
289    ```
290
291
292-   **Manually Installing Docker \(Non-Ubuntu\)**
293
294    Perform the following operations to install Docker:
295
296    ```
297    # Pull the image.
298    docker pull swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:0.0.3# Compile the Docker image in the Linux environment.
299    hpm run distWithDocker solution={product}
300    # When using Windows, make sure to configure the Git Bash.
301    hpm config set shellPath "Git Bash path"
302    hpm run distWithDocker solution={product}
303    ```
304
305