Building Images with Docker
1. Introduction to Docker
- Container: Docker uses containers to encapsulate applications and all their dependencies, including code, runtime, system tools, and libraries. Containers provide a lightweight, consistent, and portable environment that allows applications to run reliably across different systems.
- Image: An image is the blueprint for a container. It includes all necessary components such as the filesystem, libraries, and configuration needed to run a container. Images can be stored, shared, and transferred over networks.
- Repository: Images are stored in repositories for centralized management and sharing. Docker supports both public repositories (e.g., Docker Hub) and private ones. Users can pull images from repositories or push custom images for others to use or deploy.
- Installing Docker Tools (Docker Engine Installation)
sudo apt install docker.io -y - Obtaining Docker Images.
sudo docker pull luckfoxtech/luckfox_pico:1.0 - If you encounter issues accessing Docker Hub or pulling images fails, you can opt to use the offline image version instead.
Version Description Download Link luckfoxtech/luckfox_pico 1.0 Offline Docker image Docker Google Drive Link #docker Importing an Image
sudo docker load -i ./luckfox_pico_docker.tar
The steps above only install the Docker engine on the system, which serves as the container runtime platform. To actually run containers, you must explicitly start a container using commands such as docker run or docker start.
2. Building SDK Images with Docker
- Obtain the latest SDK: (You may choose either of the following two methods)
git clone https://gitee.com/LuckfoxTECH/luckfox-pico.git
git clone https://github.com/LuckfoxTECH/luckfox-pico.git - To start an interactive container named "luckfox", mount the local SDK directory on the host to the /home directory inside the container, and run it with a Bash shell:
sudo docker run -it --name luckfox --privileged -v /home/ubuntu/luckfox-pico:/home luckfoxtech/luckfox_pico:1.0 /bin/bash-it: Runs the container in interactive mode--name: Assigns a name to the container for easier identification and management-v: Mounts a directory or file from the host into the container. In the example, the host's/home/ubuntu/luckfox-picodirectory is mounted to the container's/homedirectory
- If the container already exists, you can restart it using the following command:
sudo docker start -ai luckfox - Before starting the build, make sure to select the correct code branch according to your development board model to ensure that the compiled image runs properly.
root@b165d8d4c29b:# cd /home
root@807131c0df36:/home# ./build.sh lunch
You're building on Linux
Lunch menu...pick the Luckfox Pico hardware version:
选择 Luckfox Pico 硬件版本:
[0] RV1103_Luckfox_Pico
[1] RV1103_Luckfox_Pico_Mini_A
[2] RV1103_Luckfox_Pico_Mini_B
[3] RV1103_Luckfox_Pico_Plus
[4] RV1103_Luckfox_Pico_WebBee
[5] RV1106_Luckfox_Pico_Pro
[6] RV1106_Luckfox_Pico_Max
[7] RV1106_Luckfox_Pico_Ultra
[8] RV1106_Luckfox_Pico_Ultra_W
[9] RV1106_Luckfox_Pico_Pi
[10] RV1106_Luckfox_Pico_Pi_W
[11] RV1106_Luckfox_Pico_86Panel
[12] RV1106_Luckfox_Pico_86Panel_W
[13] custom
Which would you like? [0~13][default:0]: 12
Lunch menu...pick the boot medium:
选择启动媒介:
[0] EMMC
Which would you like? [0][default:0]: 0
Lunch menu...pick the system version:
选择系统版本:
[0] Buildroot
Which would you like? [0][default:0]: 0
[build.sh:info] Lunching for Default BoardConfig_IPC/BoardConfig-EMMC-Buildroot-RV1106_Luckfox_Pico_86Panel_W-IPC.mk boards...
[build.sh:info] switching to board: /home/project/cfg/BoardConfig_IPC/BoardConfig-EMMC-Buildroot-RV1106_Luckfox_Pico_86Panel_W-IPC.mk
[build.sh:info] Running build_select_board succeeded.
root@807131c0df36:/home# ./build.sh
3. Adding Users to the Docker Group
- Run the following command to add the current user to the Docker group:
sudo usermod -aG docker $USER - Log out and log back in, or run the following command to apply the changes immediately:
sudo service docker restart
newgrp docker - Make sure the user luckfox has been successfully added to the Docker group. You can verify this with the following command:
id luckfox
4. Common Docker Commands
- Image-related commands:
docker pull luckfoxtech/luckfox_pico:1.0 # Download the image from Docker Hub.
docker images # List all local Docker images.
docker rmi luckfoxtech/luckfox_pico:1.0 # Remove one or more local images.
docker search [image] # Search for images on Docker Hub. - Container-related commands:
docker ps # List currently running containers.
docker ps -a # List all containers, including stopped ones. - Container operations:
docker start 1758 # Start a stopped container.
docker stop 1758 # Stop a running container.
docker restart 1758 # Restart a container.
docker exec -it 1758 ls # Execute a command in a running container.
docker exec -it 1758 bash # Enter a running container with an interactive shell.
docker rm 1758 # Remove one or more containers.
exit # Exit the container shell. - Running a container:
sudo docker run -it --name luckfox --privileged -v /home/ubuntu/luckfox-pico:/home luckfoxtech/luckfox_pico:1.0 /bin/bash-it: Runs the container in interactive mode--name: Assigns a name to the container for easier identification and management-v: Mounts a directory or file from the host into the container. In the example, the host's/home/ubuntu/luckfox-picodirectory is mounted to the container's/homedirectory
sudo docker start -ai luckfox # Start the Docker container interactively (e.g., second time). - System information:
docker logs 1758 # View logs from the container.
docker inspect 1758 # View detailed information about the container.
docker rmi luckfoxtech/luckfox_pico:1.0 # Remove one or more local images.
docker top 1758 # View running processes inside the container.
The Docker container ID is unique. In most cases, you can use the first few characters to uniquely identify a container. When using these commands, replace the example container ID with your own container’s ID (or its prefix).