• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Docker Environment<a name="EN-US_TOPIC_0000001055701144"></a>
2
3## Introduction<a name="section107932281315"></a>
4
5OpenHarmony provides the following two types of Docker environments for you to quickly get the development environment ready:
6
7-   Standalone Docker environment: applicable when using Ubuntu or Windows to build a distribution
8-   HPM-based Docker environment: applicable when using the HarmonyOS Package Manager \(HPM\) to build a distribution
9
10**Table  1** Docker image
11
12<a name="table11986917191214"></a>
13<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>
14</th>
15<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>
16</th>
17<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>
18</th>
19<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>
20</th>
21<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>
22</th>
23</tr>
24</thead>
25<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>
26</td>
27<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>
28</td>
29<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>
30</td>
31<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>
32</td>
33<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>1.0.0</p>
34</td>
35</tr>
36<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>
37</td>
38<td class="cellrowborder" valign="top" headers="mcps1.2.6.1.2 "><p id="p1598641741215"><a name="p1598641741215"></a><a name="p1598641741215"></a>Ubuntu</p>
39</td>
40<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</p>
41</td>
42<td class="cellrowborder" valign="top" headers="mcps1.2.6.1.4 "><p id="p1633303300"><a name="p1633303300"></a><a name="p1633303300"></a>1.0.0</p>
43</td>
44</tr>
45<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>
46</td>
47<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>
48</td>
49<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>
50</td>
51<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>
52</td>
53<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>
54</td>
55</tr>
56</tbody>
57</table>
58
59
60
61
62
63
64
65
66## Preparations<a name="section7337134183512"></a>
67
68Before using the Docker environment, perform the following operations:
69
701.  Install Docker. For details, see [Install Docker Engine](https://docs.docker.com/engine/install/).
712.  Obtain the OpenHarmony source code. For details, see [Source Code Acquisition](sourcecode-acquire.md).
72
73    > **NOTE**
74    >
75    > You do not need to obtain the source code for the HPM-based Docker environment.
76
773.  Perform subsequent operations as a user who has the root permission or has been granted the permission to use Docker.
78
79## Standalone Docker Environment<a name="section2858536103611"></a>
80
81The Docker image of OpenHarmony is hosted on HUAWEI CLOUD SWR. Using the Docker image will help simplify environment configurations needed for the building. The following describes the detailed procedure.
82
83### 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>
84
851.  Obtain the Docker image.
86
87    ```
88    docker pull swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:1.0.0
89    ```
90
912.  Go to the root directory of OpenHarmony code and run the following command to access the Docker build environment:
92
93    Run the following command in Ubuntu:
94
95    ```
96    docker run -it -v $(pwd):/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:1.0.0
97    ```
98
99    Run the following command in Windows \(assuming that the source code directory is **D:\\OpenHarmony**\):
100
101    ```
102    docker run -it -v D:\OpenHarmony:/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:1.0.0
103    ```
104
105
106### Building for Mini-System Devices \(reference memory ≥ 128 KB\) and Small-System Devices \(reference memory ≥ 1 MB\)<a name="section631485163615"></a>
107
108The following uses the Hi3516 platform as an example to describe the build procedure.
109
110Set the build path to the current path.
111
112```
113hb set
114```
115
116**Figure 1** Setting page<a name="fig7947145854013"></a>
117![](figures/setting-page.png "setting-page")
118
119> **NOTE**<br>
120> The mapping between the development board and the building GUI:
121>
122> -   Hi3861: wifiiot\_hispark\_pegasus@hisilicon
123> -   Hi3516: ipcamera\_hispark\_taurus@hisilicon
124> -   Hi3518: ipcamera\_hispark\_aries@hisilicon
125
1261.  Select **ipcamera\_hispark\_taurus@hisilicon** and press **Enter**.
1272.  Start building.
128
129    ```
130    hb build -f
131    ```
132
1333.  View the build result.
134
135    The files will be generated in the **out/hispark\_taurus/ipcamera\_hispark\_taurus** directory.
136
137
138### Setting Up the Docker Environment for Standard-System Devices \(reference memory ≥ 128 MB\)<a name="section13585262391"></a>
139
1401.  Obtain the Docker image.
141
142    ```
143    docker pull swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:1.0.0
144    ```
145
1462.  Go to the root directory of OpenHarmony code and run the following command to access the Docker build environment:
147
148    ```
149    docker run -it -v $(pwd):/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:1.0.0
150    ```
151
152
153### Building for Standard-System Devices \(reference memory ≥ 128 MB\)<a name="section193711513406"></a>
154
155Run the following script to start building for standard-system devices \(reference memory ≥ 128 MB\).
156
157```
158./build.sh --product-name {product_name} --ccache
159```
160
161**product\_name** indicates the platform supported by the current distribution, for example, hispark_taurus_standard and rk3568.
162
163Files generated during building are stored in the **out/{device_name}/** directory, and the generated image is stored in the **out/{device_name}/packages/phone/images/** directory.
164
165
166>![](../public_sys-resources/icon-note.gif) **NOTE**<br>
167>You can exit Docker by simply running the **exit** command.
168
169## HPM-based Docker Environment<a name="section485713518337"></a>
170
171**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 development environments, perform the following steps to access the Docker environment:
172
173### Setting Up the Docker Environment<a name="section3295842510"></a>
174
1751.  Initialize the installation template by running the following command in any of the working directories:
176
177    ```
178    hpm init -t @ohos/docker_dist
179    ```
180
1812.  Modify the **publishAs** field.
182
183    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.
184
185
186### Obtaining and Building Source Code<a name="section69141039143518"></a>
187
188Start building. Docker can be automatically installed only in Ubuntu. If you are using any other operating system, manually install Docker before pulling the image.
189
190-  **Automatically Installing Docker \(Ubuntu\)**
191
192    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.
193
194   **Method 1:**
195
196    Add a parameter to specify the solution. For example:
197
198    ```
199    hpm run docker solution={product}
200    ```
201
202   **\{product\}** indicates the solution, for example, **@ohos/hispark\_taurus**, **@ohos/hispark\_aries**, and **@ohos/hispark\_pegasus**.
203
204   **Method 2:**
205
206    Set an environment variable to specify the solution, and then run the build command.
207
208    1.  Select the desired solution.
209
210        ```
211        export solution={product}
212        ```
213
214       **\{product\}** indicates the solution, for example, **@ohos/hispark\_taurus**, **@ohos/hispark\_aries**, and **@ohos/hispark\_pegasus**.
215
216    2.  Obtain and build the source code.
217
218        ```
219        hpm run docker
220        ```
221
222    This example uses the **@ohos/hispark\_taurus** solution for illustration. If the execution is successful, the output is as follows:
223
224    ```
225    ...
226    ohos ipcamera_hispark_taurus build success!
227    @ohos/hispark_taurus: distribution building completed.
228    ```
229
230
231-  **Manually Installing Docker \(Non-Ubuntu\)**
232
233    Perform the following operations to install Docker:
234
235    ```
236    # Pull the image.
237    docker pull swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:0.0.3# Compile the Docker image in the Linux environment.
238    hpm run distWithDocker solution={product}
239    # When using Windows, make sure to configure the Git Bash.
240    hpm config set shellPath "Git Bash path"
241    hpm run distWithDocker solution={product}
242    ```
243
244