Docker Usage

Docker Support

The normal firmware released by Neardi generally does not meet the requirements for Docker, so if you need to, you can use the SDK to open the kernel’s configuration and recompile and burn the kernel to support Docker.

The following example is based on Neardi Ubuntu 20.04, and the kernel configuration part is generic!

Checking Kernel Configuration

The first thing you need to do is to tool around and check which Docker-needed configurations are missing from the current device’s kernel. The check-config.sh script can be obtained from github.

After getting the script, the inspection started:

# Copy the script to the kernel directory of the SDK
cp check-config.sh PathToSDK/kernel/
cd PathToSDK/kernel
chmod +x check-config.sh

# Get the current kernel configuration
make ARCH=arm64 rockchip_linux_defconfig

# Detection
./check-config.sh .config

The result after execution is as follows, with two main parts:

Generally Necessary:
- cgroup hierarchy: properly mounted [/sys/fs/cgroup]
- apparmor: enabled and tools installed
- CONFIG_NAMESPACES: enabled
- CONFIG_NET_NS: enabled
- CONFIG_PID_NS: enabled
- CONFIG_IPC_NS: enabled
- CONFIG_UTS_NS: enabled
- CONFIG_CGROUPS: enabled
......

Optional Features:
- CONFIG_USER_NS: enabled
- CONFIG_SECCOMP: enabled
- CONFIG_SECCOMP_FILTER: enabled
- CONFIG_CGROUP_PIDS: enabled
- CONFIG_MEMCG_SWAP: enabled
......

Generally Necessary: Indicates a necessary configuration, if there is something that shows missing, you need to turn it on in the kernel configuration. Optional Features: is an optional configuration, turn it on as needed.

Turning on Required Features

Once you know what you need to turn on from the above test results, you can use make ARCH=arm64 menuconfig to enter the menu and search for the corresponding item to turn it on. Please check the instructions in the menu carefully, and pay attention to the dependencies of the unselectable items.

After you have opened all the necessary configurations and some of the optional configurations, save them:

make ARCH=arm64 savedefconfig
mv defconfig arch/arm64/configs/rockchip_linux_defconfig

After that, compile the kernel:

# Return to the SDK directory
cd ..
# Compile the kernel
./build.sh kernel

Installing Docker

After burning the new kernel, you can start installing Docker on your device (this installation method also applies to PCs):

  • Step 1: Quick Installation

# Here we only introduce the quick installation using scripts directly
apt-get update
wget -qO- https://get.docker.com/ | sh

Wait for the installation to complete and you should see the Docker version information.

  • Step 2: Check docker storage location (this step only applies to PC installations of docker)

If you are installing docker on a Neardi device, skip step 2

# Execute
docker info | grep -i dir
# Execute Result
 Docker Root Dir: /var/lib/docker

The information returned shows the default storage location for docker, which may be different on different computers Images and containers take up a lot of space, so if the default location doesn’t have a lot of space, you need to change it to a location with plenty of space

**Emphasize again that this step is only for PCs and Neardi devices, modifying this location will cause docker to not work, so please skip to the next step.

# First shut down the docker service
sudo systemctl stop docker

# Modify the file /lib/systemd/system/docker.service
sudo vim /lib/systemd/system/docker.service

# Add the location you want to modify at the end of this line --graph /home/neardi/docker/data
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --graph /home/neardi/docker/data

# Restart the docker service
sudo systemctl daemon-reload
sudo systemctl start docker

# Check whether the location has been modified successfully
docker info | grep -i dir
Docker Root Dir: /home/neardi/docker/data
  • Step 3: Add your own user to the docker group

sudo usermod -a -G docker neardi
# Restart after adding
sudo reboot
  • Step 4: Reboot and run the demo to test if it works:

neardi@LPA3588:~$ docker run hello-world

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (arm64v8)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/