Docker on Rock 4C+ with Debian

On Debian you can get some problems with running docker. After installed docker by

curl -o - https://get.docker.com | sudo sh

probably docker wont start:

rock@rock-4c-plus:~$ sudo systemctl start docker
Job for docker.service failed because the control process exited with error code.
See "systemctl status docker.service" and "journalctl -xe" for details.
rock@rock-4c-plus:~$ sudo systemctl status docker
● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Thu 2023-01-26 13:23:06 UTC; 25s ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
    Process: 4613 ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock (code=exited, status=1/FAILURE)
   Main PID: 4613 (code=exited, status=1/FAILURE)

Jan 26 13:23:03 rock-4c-plus systemd[1]: docker.service: Failed with result 'exit-code'.
Jan 26 13:23:03 rock-4c-plus systemd[1]: Failed to start Docker Application Container Engine.
Jan 26 13:23:06 rock-4c-plus systemd[1]: docker.service: Scheduled restart job, restart counter is at 3.
Jan 26 13:23:06 rock-4c-plus systemd[1]: Stopped Docker Application Container Engine.
Jan 26 13:23:06 rock-4c-plus systemd[1]: docker.service: Start request repeated too quickly.
Jan 26 13:23:06 rock-4c-plus systemd[1]: docker.service: Failed with result 'exit-code'.
Jan 26 13:23:06 rock-4c-plus systemd[1]: Failed to start Docker Application Container Engine.
Jan 26 13:23:25 rock-4c-plus systemd[1]: docker.service: Start request repeated too quickly.
Jan 26 13:23:25 rock-4c-plus systemd[1]: docker.service: Failed with result 'exit-code'.
Jan 26 13:23:25 rock-4c-plus systemd[1]: Failed to start Docker Application Container Engine.

So… problem is related with iptables (iptables wont works also). You can just run dockerd command and see real error:

rock@rock-4c-plus:~$ sudo dockerd
INFO[2023-01-26T13:24:47.874169777Z] Starting up                                  
INFO[2023-01-26T13:24:47.877662675Z] parsed scheme: "unix"                         module=grpc
INFO[2023-01-26T13:24:47.877740839Z] scheme "unix" not registered, fallback to default scheme  module=grpc
INFO[2023-01-26T13:24:47.877817545Z] ccResolverWrapper: sending update to cc: {[{unix:///run/containerd/containerd.sock  <nil> 0 <nil>}] <nil> <nil>}  module=grpc
INFO[2023-01-26T13:24:47.877850794Z] ClientConn switching balancer to "pick_first"  module=grpc
INFO[2023-01-26T13:24:47.881145947Z] parsed scheme: "unix"                         module=grpc
INFO[2023-01-26T13:24:47.881240445Z] scheme "unix" not registered, fallback to default scheme  module=grpc
INFO[2023-01-26T13:24:47.881314526Z] ccResolverWrapper: sending update to cc: {[{unix:///run/containerd/containerd.sock  <nil> 0 <nil>}] <nil> <nil>}  module=grpc
INFO[2023-01-26T13:24:47.881347192Z] ClientConn switching balancer to "pick_first"  module=grpc
INFO[2023-01-26T13:24:47.894612677Z] [graphdriver] using prior storage driver: overlay2 
WARN[2023-01-26T13:24:47.908022534Z] Unable to find cpu controller                
WARN[2023-01-26T13:24:47.908088740Z] Unable to find io controller                 
WARN[2023-01-26T13:24:47.908106531Z] Unable to find cpuset controller             
INFO[2023-01-26T13:24:47.908568809Z] Loading containers: start.                   
INFO[2023-01-26T13:24:47.948959958Z] unable to detect if iptables supports xlock: 'iptables --wait -L -n': `iptables v1.8.7 (nf_tables): Could not fetch rule set generation id: Invalid argument`  error="exit status 4"
INFO[2023-01-26T13:24:48.656481769Z] stopping event stream following graceful shutdown  error="<nil>" module=libcontainerd namespace=moby
failed to start daemon: Error initializing network controller: error obtaining controller instance: failed to create NAT chain DOCKER: iptables failed: iptables -t nat -N DOCKER: iptables v1.8.7 (nf_tables): Could not fetch rule set generation id: Invalid argument

 (exit status 4)

As we see docker have problem with iptables. Problem exists because you have kernel 4.x, but new iptables required kernel 5.x or above, so you have to replace current iptables with iptables-legacy, by these commands:

sudo update-alternatives --set iptables /usr/sbin/iptables-legacy

Now you can run docker:

sudo systemctl start docker

Lets run first container:

root@rock-4c-plus:/home/rock# sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
7050e35b49f5: Pull complete 
Digest: sha256:aa0cc8055b82dc2509bed2e19b275c8f463506616377219d9642221ab53cf9fe
Status: Downloaded newer image for hello-world:latest
ERRO[0007] error waiting for container: context canceled 
docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: cgroup namespaces aren't enabled in the kernel: unknown.

Yaay, another error! 🙂 Now we have to add to file /boot/extlinux/extlinux.conf these argument:

#timeout 10
#menu title select kernel

label kernel-4.4.194-11-rk3399-rockchip-g1bb08d49cc40
    kernel /vmlinuz-4.4.194-11-rk3399-rockchip-g1bb08d49cc40
    initrd /initrd.img-4.4.194-11-rk3399-rockchip-g1bb08d49cc40
    devicetreedir /dtbs/4.4.194-11-rk3399-rockchip-g1bb08d49cc40
    append earlyprintk console=ttyFIQ0,1500000n8 rw init=/sbin/init rootfstype=ext4 rootwait  root=UUID=63e973d2-653e-4174-9ac7-63bb03114e2b console=ttyS2,1500000n8 systemd.unified_cgroup_hierarchy=0

Now you have to reboot ROCK. After fresh start you can run container again:

rock@rock-4c-plus:~$ sudo 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/

Hurraaa! It works.

BTW, if you want buy ROCK board you can do this here: https://sklep.wizro.pl/szukaj?controller=search&s=rock

With code BE-A-ROOT you will get 5% discount!

Protip 1: add user to docker group for using docker command without sudo:

sudo usermod -a -G docker rock