I have a number of raspberries at home, these microcomputers the size of credit cards. Small and powerful, they have many uses, such as having a mediacenter on a TV set too old to do it natively.
I even recently fell for the Raspberry Pi 4 released last month (I'm weak against a new toy) to turn it into an application server, with its 4Gb of RAM, there's plenty to do.
After installing a raspbian 10 (buster) "lite" distribution (available here), I decided to install docker on it in order to run my applications in containers.
You will find below how I did this installation.
We start by installing the docker requirements
#Update packet cache sudo apt update #Installing the necessary binaries sudo apt -y install apt-transport-https ca-certificates curl gnupg2 software-properties-common
Then, we add the repository (at the time I'm writing these lines, adding via add-apt-repository returns an error) :
#Adding the GPG Docker key curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add - #Adding the repository sudo echo "deb https://download.docker.com/linux/raspbian/ stretch stable" >> /etc/apt/sources.list
We can then install docker, with a small nuance. Indeed in the recommended packages is aufs-dkms, this package does not manage to compile correctly on the raspberry, so you have to install docker without its recommended packages.
#Update packet cache sudo apt update #Installing Docker without its recommended packages sudo apt -y install docker-ce --no-install-recommends
A small test with a "hello-world" allows us to see that our little docker is doing well:
[email protected]:/home/pi# docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world c1eda109e4da: Pull complete Digest: sha256:6540fc08ee6e6b7b63468dc3317e3303aae178cb8a45ed3123180328bcc1d20f Status: Downloaded newer image for hello-world:latest 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. (arm32v7) 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/
To ensure that Docker restarts at the same time as the raspberry, the associated service must be activated via systemctl
[email protected]:/home/pi# systemctl enable docker.service Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/docker.service.
We can also activate the support of the RAM limit per container, one of the main interests of containerization, to do this we will modify the file /boot/cmdline.txt and add the following commands :
which gives, as far as I'm concerned:
[email protected]:/home/pi# more /boot/cmdline.txt dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=PARTUUID=ac55fd9e-02 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait cgroup_enable=me
then, it is necessary to reboot the raspberry so that the modifications are taken into account.
From there, you normally have a docker server ready to use. It is also possible to install docker-composite for example.
Personally, I tried to install kubernetes (for sport), but I was unable to debug the network stack which was not working, because of a problem in the coredns pod. I'll probably try again later.
It is noted that some problems I encountered are probably due to the youth of the Debian version used (Debian released on July 6th, Raspbian released on the 10th, I installed it on the 12th), which means that a lot of packages are not officially available on it, but still on stretch, which doesn't guarantee their optimal functioning.