1e41f4b71Sopenharmony_ci# Docker Environment 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ci## Introduction 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ciOpenHarmony provides the following two types of docker environments for you to quickly get the development environment ready: 7e41f4b71Sopenharmony_ci 8e41f4b71Sopenharmony_ci- Standalone Docker environment: applicable when using Ubuntu or Windows to build a distribution 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci- HPM-based Docker environment: applicable when using the HarmonyOS Package Manager (HPM) to build a distribution 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci**Table 1** Docker environments 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci| System Type| Operating Platform| Docker Image Repository| Tag| 15e41f4b71Sopenharmony_ci| -------- | -------- | -------- | -------- | 16e41f4b71Sopenharmony_ci| Standard system (standalone Docker environment)| Ubuntu/Windows | swr.cn-south-1.myhuaweicloud.com/openharmony-docker/docker_oh_standard | 3.2 | 17e41f4b71Sopenharmony_ci| Small system (standalone Docker environment)| Ubuntu/Windows | swr.cn-south-1.myhuaweicloud.com/openharmony-docker/docker_oh_small | 3.2 | 18e41f4b71Sopenharmony_ci| Mini system (standalone Docker environment)| Ubuntu/Windows | swr.cn-south-1.myhuaweicloud.com/openharmony-docker/docker_oh_mini | 3.2 | 19e41f4b71Sopenharmony_ci| Mini and small systems (HPM Docker environment)| Ubuntu/Windows | swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker | 0.0.3 | 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci## Setting Up Environment 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ciBefore using the Docker environment, you need to make necessary preparations. The following uses Ubuntu as an example to describe the specific preparations. 25e41f4b71Sopenharmony_ci 26e41f4b71Sopenharmony_ci1. Installing Docker 27e41f4b71Sopenharmony_ci - Install Docker. 28e41f4b71Sopenharmony_ci ``` 29e41f4b71Sopenharmony_ci sudo apt install docker.io 30e41f4b71Sopenharmony_ci ``` 31e41f4b71Sopenharmony_ci - For details about how to install Docker on other types of OS, see [Docker Guide](https://docs.docker.com/engine/install/). 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci2. Obtain the OpenHarmony source code. 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ci For details, see [Source Code Acquisition](sourcecode-acquire.md). 36e41f4b71Sopenharmony_ci > **NOTE**<br> 37e41f4b71Sopenharmony_ci > You do not need to obtain the source code for the HPM-based Docker environment. 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_ci3. Obtaining the required permissions. 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci Perform subsequent operations as a user who has the root permission or has been granted the permission to use Docker. On Ubuntu, you can add **sudo** before a command to obtain the **root** permission. On Windows, you may need to run **cmd** or **PowerShell** in administrator mode. 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci## Standalone Docker Environment 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ciA Docker image is a lightweight executable software package that contains applications and runtimes. Docker images of OpenHarmony are hosted on HuaweiCloud SWR. Using the Docker image will help simplify environment configurations needed for the building. The following describes the detailed procedure. 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci### Setting Up the Docker Environment for Mini- and Small-System Devices 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci1. Obtain the Docker image. 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci For mini-system devices: 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci ``` 54e41f4b71Sopenharmony_ci docker pull swr.cn-south-1.myhuaweicloud.com/openharmony-docker/docker_oh_small:3.2 55e41f4b71Sopenharmony_ci ``` 56e41f4b71Sopenharmony_ci For small-system devices: 57e41f4b71Sopenharmony_ci ``` 58e41f4b71Sopenharmony_ci docker pull swr.cn-south-1.myhuaweicloud.com/openharmony-docker/docker_oh_mini:3.2 59e41f4b71Sopenharmony_ci ``` 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ci2. Access the Docker build environment. 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci After obtaining the Docker image, you need to create a Docker container and access the container. Go to the root directory of OpenHarmony source code and run the respective command to access the Docker build environment. 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ci - Ubuntu 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ci ``` 68e41f4b71Sopenharmony_ci # For mini-system devices 69e41f4b71Sopenharmony_ci docker run -it -v $(pwd):/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/docker_oh_small:3.2 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ci # For small-system devices: 72e41f4b71Sopenharmony_ci docker run -it -v $(pwd):/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/docker_oh_mini:3.2 73e41f4b71Sopenharmony_ci ``` 74e41f4b71Sopenharmony_ci 75e41f4b71Sopenharmony_ci - Windows (example source code directory: `D:\OpenHarmony`) 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ci ``` 78e41f4b71Sopenharmony_ci # For mini-system devices 79e41f4b71Sopenharmony_ci docker run -it -v D:\OpenHarmony:/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/docker_oh_small:3.2 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ci # For small-system devices: 82e41f4b71Sopenharmony_ci docker run -it -v D:\OpenHarmony:/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/docker_oh_mini:3.2 83e41f4b71Sopenharmony_ci ``` 84e41f4b71Sopenharmony_ci 85e41f4b71Sopenharmony_ci > **NOTE**<br> 86e41f4b71Sopenharmony_ci > `docker run -it -v $(pwd):/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/docker_oh_small:3.2`: used to create an OpenHarmony Docker container that runs in interactive mode and maps the current directory to the `/home/openharmony` directory of the container. 87e41f4b71Sopenharmony_ci 88e41f4b71Sopenharmony_ci### Building for Mini- and Small-System Devices 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ci1. Run the build script. 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci Run `docker run` to access the Docker container in `/home/openharmony`. Then, run the build script to start building for mini-system devices (reference memory ≥ 128 KiB) and small-system devices (reference memory ≥ 1 MiB). 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_ci ``` 95e41f4b71Sopenharmony_ci python3 build.py -p {product_name}@{company} 96e41f4b71Sopenharmony_ci ``` 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ci where, `{product_name}` indicates the platform supported by the current version, and `{company}` indicates the company name. 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_ci For example, to start building for `ipcamera_hispark_taurus` of `hisilicon`, use the following command: 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci ``` 103e41f4b71Sopenharmony_ci python3 build.py -p ipcamera_hispark_taurus@hisilicon 104e41f4b71Sopenharmony_ci ``` 105e41f4b71Sopenharmony_ci 106e41f4b71Sopenharmony_ci Similarly, to start building for `qemu_small_system_demo` of `ohemu`, use the following command: 107e41f4b71Sopenharmony_ci 108e41f4b71Sopenharmony_ci ``` 109e41f4b71Sopenharmony_ci python3 build.py -p qemu_small_system_demo@ohemu 110e41f4b71Sopenharmony_ci ``` 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_ci2. View the build result. 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_ci The files generated during the build are stored in `out/{device_name}/`, and the resulting images are stored in `out/{device_name}/packages/phone/images/`. 115e41f4b71Sopenharmony_ci 116e41f4b71Sopenharmony_ci> **NOTE**<br> 117e41f4b71Sopenharmony_ci> To exit Docker, run `exit`. This command stops the current Docker container and goes back to your OS. 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_ci### Setting Up the Docker Environment for Standard-System Devices 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ci1. Obtain the Docker image. 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ci Before setting up a Docker environment for standard-system devices, you need to obtain the corresponding Docker image by running the following command: 124e41f4b71Sopenharmony_ci 125e41f4b71Sopenharmony_ci ``` 126e41f4b71Sopenharmony_ci docker pull swr.cn-south-1.myhuaweicloud.com/openharmony-docker/docker_oh_standard:3.2 127e41f4b71Sopenharmony_ci ``` 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ci2. Access the Docker build environment. 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ci Same as the previous procedure, you need to create a new Docker container and access the container. Go to the root directory of OpenHarmony source code and run the respective command to access the Docker build environment. 132e41f4b71Sopenharmony_ci 133e41f4b71Sopenharmony_ci - Ubuntu 134e41f4b71Sopenharmony_ci 135e41f4b71Sopenharmony_ci ``` 136e41f4b71Sopenharmony_ci docker run -it -v $(pwd):/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/docker_oh_standard:3.2 137e41f4b71Sopenharmony_ci ``` 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_ci - Windows (example source code directory: D:\OpenHarmony) 140e41f4b71Sopenharmony_ci 141e41f4b71Sopenharmony_ci ``` 142e41f4b71Sopenharmony_ci docker run -it -v D:\OpenHarmony:/home/openharmony swr.cn-south-1.myhuaweicloud.com/openharmony-docker/docker_oh_standard:3.2 143e41f4b71Sopenharmony_ci ``` 144e41f4b71Sopenharmony_ci 145e41f4b71Sopenharmony_ci### Building for Standard-System Devices 146e41f4b71Sopenharmony_ci 147e41f4b71Sopenharmony_ci1. Run the build script. 148e41f4b71Sopenharmony_ci 149e41f4b71Sopenharmony_ci Run `docker run` to access the Docker container in `/home/openharmony`. Then, run the build script to start building for standard-system devices (reference memory ≥ 128 MiB). 150e41f4b71Sopenharmony_ci 151e41f4b71Sopenharmony_ci ``` 152e41f4b71Sopenharmony_ci ./build.sh --product-name {product_name} --ccache 153e41f4b71Sopenharmony_ci ``` 154e41f4b71Sopenharmony_ci 155e41f4b71Sopenharmony_ci `{product_name}` indicates the platform supported by the current distribution. For example, if `{product_name}` is `rk3568`, run the following command to start building: 156e41f4b71Sopenharmony_ci 157e41f4b71Sopenharmony_ci ``` 158e41f4b71Sopenharmony_ci ./build.sh --product-name rk3568 --ccache 159e41f4b71Sopenharmony_ci ``` 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_ci2. View the build result. 162e41f4b71Sopenharmony_ci Files generated during the build are stored in `out/{device_name}/`, and the generated image is stored in `out/{device_name}/packages/phone/images/`. 163e41f4b71Sopenharmony_ci 164e41f4b71Sopenharmony_ci> **NOTE**<br> 165e41f4b71Sopenharmony_ci> To exit Docker, run `exit`. This command stops the current Docker container and goes back to your OS. 166e41f4b71Sopenharmony_ci 167e41f4b71Sopenharmony_ci 168e41f4b71Sopenharmony_ci## HPM-based Docker Environment 169e41f4b71Sopenharmony_ci 170e41f4b71Sopenharmony_ci**docker_dist** is a template component in the [HPM](https://hpm.harmonyos.com/) system. It helps to quickly initialize an HPM project and use the Docker image to quickly build a distribution of , greatly simplifying environment configurations needed for building. After configuring the Ubuntu and [hpm-cli](https://device.harmonyos.com/cn/docs/documentation/guide/hpm-part-development-install-0000001178291102) development environments, perform the following steps to access the Docker environment: 171e41f4b71Sopenharmony_ci 172e41f4b71Sopenharmony_ci 173e41f4b71Sopenharmony_ci### Setting Up the Docker Environment 174e41f4b71Sopenharmony_ci 175e41f4b71Sopenharmony_ci1. Initialize the installation template. 176e41f4b71Sopenharmony_ci 177e41f4b71Sopenharmony_ci Run the following command in any of the working directories: 178e41f4b71Sopenharmony_ci 179e41f4b71Sopenharmony_ci ``` 180e41f4b71Sopenharmony_ci hpm init -t @ohos/docker_dist 181e41f4b71Sopenharmony_ci ``` 182e41f4b71Sopenharmony_ci 183e41f4b71Sopenharmony_ci2. Modify the **publishAs** field. 184e41f4b71Sopenharmony_ci 185e41f4b71Sopenharmony_ci 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. 186e41f4b71Sopenharmony_ci 187e41f4b71Sopenharmony_ci 188e41f4b71Sopenharmony_ci### Obtaining and Building Source Code 189e41f4b71Sopenharmony_ci 190e41f4b71Sopenharmony_ciStart building. Docker can be automatically installed only in Ubuntu. If you are using any other operating system, manually install Docker before pulling the image. 191e41f4b71Sopenharmony_ci 192e41f4b71Sopenharmony_ci- Automatical installation (Ubuntu)<br> 193e41f4b71Sopenharmony_ci 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. 194e41f4b71Sopenharmony_ci 195e41f4b71Sopenharmony_ci Method 1: 196e41f4b71Sopenharmony_ci 197e41f4b71Sopenharmony_ci Add a parameter to specify the solution. For example: 198e41f4b71Sopenharmony_ci 199e41f4b71Sopenharmony_ci 200e41f4b71Sopenharmony_ci ``` 201e41f4b71Sopenharmony_ci hpm run docker solution={product} 202e41f4b71Sopenharmony_ci ``` 203e41f4b71Sopenharmony_ci 204e41f4b71Sopenharmony_ci **{product}** indicates the solution, for example, **\@ohos/hispark_taurus**, **\@ohos/hispark_aries**, or **\@ohos/hispark_pegasus**. 205e41f4b71Sopenharmony_ci 206e41f4b71Sopenharmony_ci Method 2: 207e41f4b71Sopenharmony_ci 208e41f4b71Sopenharmony_ci Set an environment variable to specify the solution, and then run the build command. 209e41f4b71Sopenharmony_ci 210e41f4b71Sopenharmony_ci 1. Select the desired solution. 211e41f4b71Sopenharmony_ci 212e41f4b71Sopenharmony_ci ``` 213e41f4b71Sopenharmony_ci export solution={product} 214e41f4b71Sopenharmony_ci ``` 215e41f4b71Sopenharmony_ci 216e41f4b71Sopenharmony_ci **{product}** indicates the solution, for example, **\@ohos/hispark_taurus**, **\@ohos/hispark_aries**, and **\@ohos/hispark_pegasus**. 217e41f4b71Sopenharmony_ci 2. Obtain and build the source code. 218e41f4b71Sopenharmony_ci 219e41f4b71Sopenharmony_ci ``` 220e41f4b71Sopenharmony_ci hpm run docker 221e41f4b71Sopenharmony_ci ``` 222e41f4b71Sopenharmony_ci 223e41f4b71Sopenharmony_ci This example uses the **\@ohos/hispark_taurus** solution for illustration. If the execution is successful, the output is as follows: 224e41f4b71Sopenharmony_ci 225e41f4b71Sopenharmony_ci ``` 226e41f4b71Sopenharmony_ci ...... 227e41f4b71Sopenharmony_ci ohos ipcamera_hispark_taurus build success! 228e41f4b71Sopenharmony_ci @ohos/hispark_taurus: distribution building completed. 229e41f4b71Sopenharmony_ci ``` 230e41f4b71Sopenharmony_ci 231e41f4b71Sopenharmony_ci- Manual installation (Non-Ubuntu)<br> 232e41f4b71Sopenharmony_ci Perform the following operations to install Docker: 233e41f4b71Sopenharmony_ci 234e41f4b71Sopenharmony_ci 235e41f4b71Sopenharmony_ci ``` 236e41f4b71Sopenharmony_ci # Pull an image. 237e41f4b71Sopenharmony_ci docker pull swr.cn-south-1.myhuaweicloud.com/openharmony-docker/openharmony-docker:0.0.3# Build the Docker image in the Linux environment. 238e41f4b71Sopenharmony_ci hpm run distWithDocker solution={product} 239e41f4b71Sopenharmony_ci # On Windows, make sure to configure the Git Bash. 240e41f4b71Sopenharmony_ci hpm config set shellPath "Git Bash path" 241e41f4b71Sopenharmony_ci hpm run distWithDocker solution={product} 242e41f4b71Sopenharmony_ci ``` 243