docker-for-raspberry-pi

With Docker on Raspberry Pi cluster, you can run any containerized applications on your Pi Cluster


Docker on Raspberry

(Total Setup Time: 15 mins)

To install Docker for Raspberry Pi Cluster, add ubuntu user to the docker group:

sudo apt install docker.io
sudo usermod -aG docker ubuntu
su - ubuntu # open a new shell with updated membership for the user

Configuring Docker

(5 mins)

Firstly, to configure docker daemon using external storage, open this system file:

sudo nano /lib/systemd/system/docker.service

Next, add the –data-root option to the ExecStart, similar to this:

ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --data-root=/mnt/hdd/docker/docker-data

You may check and restart the docker status by:

systemctl status docker
sudo systemctl stop docker
sudo systemctl daemon-reload
sudo systemctl start docker

Finally, this is my docker info:

docker-info


Test Docker

(5 mins)

You may test the docker installation by running:

docker run hello-world

This is the my first hello-world docker run:

docker-hello-world


Use local images for MicroK8s

(5 mins)

The hello-world image is only known to Docker and is invisible to MicroK8s. To export the previously built image, inject it to MicroK8s:

docker save hello-world > hello-world-image.tar
microk8s ctr image import hello-world-image.tar

You may search for the hello-world image with this command, microk8s ctr images ls. This is my result:

hello-world-import


Troubleshooting

Job for docker.service failed because the control process exited with error code

If your docker is unable to start, check on the details:

journalctl -u docker

docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock.

On further checks with journalctl, I notice that there are some errors:

failed to start daemon: remote I/O error
failed to start daemon: error initialising graphdriver: driver not supported
failed to mount overlay; invalid argument storage-driver=overlay2

It seems like for my case, the errors are cleared when this file is removed:

sudo rm /etc/docker/daemon.json

standard_init_linux.go:211: exec user process caused “permission denied”

When docker runs with the above error, the error log shows:

level=warning msg="auplink flush failed: " error="exec: \"auplink\": executable file not found in $PATH" method=Unmount storage-driver=aufs

Following dockerd options, I tried adding below option to /lib/systemd/system/docker.service. But this fails too:

--storage-driver=overlay2

Finally, I decided to format my existing ntfs HDD to ext4 using sudo mkfs.ext4 /dev/sda1. By adding the following to /etc/fstab:

UUID=[UUID] /mnt/hdd ext4 defaults 0 2

Voila! Docker on Raspberry Pi Cluster works perfectly magically!

WARNING: No swap limit support

I removed this warning by editing /boot/firmware/cmdline.txt and adding the below option to the end of the line:

swapaccount=1

This is my final Raspberry Pi firmware boot-up setting:

net.ifnames=0 dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=LABEL=writable rootfstype=ext4 elevator=deadline rootwait fixrtc cgroup_enable=memory cgroup_memory=1 swapaccount=1