Skip to main content

SDK Image Compilation (Docker Environment)

1. Introduction to Docker

Docker is a lightweight containerization platform used for packaging, distributing, and running applications along with their dependencies. Based on container technology, Docker encapsulates an application and all the required runtime environment into an isolated and portable container, ensuring consistent operation across different environments. This greatly enhances the efficiency of development, deployment, and scalability. At the core of Docker is the concept of using images to define the application and its runtime environment, and running them in containers. Containers can run seamlessly on any operating system or cloud platform that supports Docker, offering advantages such as lightness, efficiency, and isolation.
  • 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.
  1. Installing Docker Tools (Docker Engine Installation)
    sudo apt install docker.io -y
  2. Obtaining Docker Images.
    sudo docker pull luckfoxtech/luckfox_pico:1.0 
  3. If you encounter issues accessing Docker Hub or pulling images fails, you can opt to use the offline image version instead.
    VersionDescriptionDownload Link
    luckfoxtech/luckfox_pico 1.0Offline Docker imageDocker Google Drive Link
    #docker Importing an Image
    sudo docker load -i ./luckfox_pico_docker.tar
[Tip]

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

  1. 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
  2. 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-pico directory is mounted to the container's /home directory
  3. If the container already exists, you can restart it using the following command:
    sudo docker start -ai luckfox
  4. 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

On Ubuntu systems, sudo is required when running Docker commands because the Docker daemon runs with root user privileges by default. Docker performs operations that require elevated permissions, such as accessing system resources, managing containers, building images, and mounting file systems, to ensure system security and stability. If you want to run Docker commands without using sudo each time, you can add your current user to the docker group.
  1. Run the following command to add the current user to the Docker group:
    sudo usermod -aG docker $USER
  2. Log out and log back in, or run the following command to apply the changes immediately:
    sudo service docker restart
    newgrp docker
  3. 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

Here is a selection of commonly used Docker commands. To view the full list of commands and help information, run docker --help.
  1. 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.
  2. Container-related commands:
    docker ps                                     # List currently running containers.
    docker ps -a # List all containers, including stopped ones.
  3. 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.
  4. 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-pico directory is mounted to the container's /home directory
    sudo docker start -ai luckfox                 # Start the Docker container interactively (e.g., second time).
  5. 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.
  6. 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).