Installing Docker on Raspbian for the Raspberry Pi
The hardware choice is very obviously the Raspberry Pi, and to be more exact it’s the brand new Raspberry Pi 3 Model B+. This Raspberry Pi model has the following specs;
- Broadcom BCM2837B0, Cortex-A53 (ARMv8) 64-bit SoC (1.4GHz)
- 1GB LPDDR2 SDRAM
- 2.4GHz and 5GHz IEEE 802.11.b/g/n/ac wireless LAN, Bluetooth 4.2, BLE
- Gigabit Ethernet over USB 2.0 (however the maximum throughput is around ~300 Mb/ps)
- 5V/2.5A DC power input (however it can run on 2A power adapter just fine)
For the Operating System I’m going for Raspbian Strecth Lite.
although the processor that comes with the Raspberry Pi 3B+ is a 64 bit’s CPU, Raspbian is not 64 bits. At this moment all Raspbian versions are 32 bits only 😥
Let’s get started but first let’s confirm that the processor is a ARMv8. Let’s run the uname command to verify this;
$ uname -m armv7l
Euh, this can’t be right? … the uname command shows us that the processor is a ARMv7 where it should be an ARMv8.
Unfortunately this is because Raspbian is still running with the same 32-bit kernel as the 2B that have a ARMv7 processor. So it will report that it have a ARMv7 when your using a 32-bit kernel.
So the hardware side is a ARMv8 but on the software side it will be shown as a 32 bits ARMv7.
Just like the previous post on how to install Docker on Armbian, we could use the Docker supplied repositories. This is because Rasbpian is just like Armbian so it’s based on Debian, and Docker will provide installation sources for Debian based systems.
The first task is to install the required packages and configure the Docker repository.
Lets start with installing the packages.
$ sudo apt install -y \ apt-transport-https \ ca-certificates \ curl \ gnupg \ gpgv
Once the packages have been installed the next step is to add the Docker GPG key.
$ curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
The next step is to add the Docker repository.
$ echo "deb [arch=armhf] https://download.docker.com/linux/debian \ $(lsb_release -cs) stable" | \ sudo tee /etc/apt/sources.list.d/docker.list
Tell the system there is a new repository available we need run a update command
$ sudo apt update
When running the update command you should see there are two Docker repositories added to the repo list.
NOTE: it’s only required to run a update and not the upgrade command 😉
Once all the previous commands have been run successfully, it’s time to install Docker!
$ sudo apt install -y docker-ce
Great Docker has been installed, now the final step is to check if it’s running asARMv7.
$ docker version
This should show you an output that consist of two parts; one is the Docker Client and one is the Docker Engine, both should show ARMv7 at the OS/Arch section.
$ docker version Client: Version: 18.03.0-ce API version: 1.37 Go version: go1.9.4 Git commit: 0520e24 Built: Wed Mar 21 23:18:37 2018 OS/Arch: linux/arm Experimental: false Orchestrator: swarm Server: Engine: Version: 18.03.0-ce API version: 1.37 (minimum version 1.12) Go version: go1.9.4 Git commit: 0520e24 Built: Wed Mar 21 23:14:43 2018 OS/Arch: linux/arm Experimental: false
If you see any error’s on the server side, than perhaps you need to add your account to the docker group;
$ sudo addgroup [your account] docker
Great everything is installed and running with ARMv7 support.
Lets try to start a Alpine container.
$ docker run -it alpine sh $ exit
And run the command to check what CPU architecture it’s running.
$ docker run -it alpine uname -a Linux dc6ec2b6a1a3 4.14.30-v7+ #1102 SMP Mon Mar 26 16:45:49 BST 2018 armv7l Linux
As you can see the container is running as ARMv7, so we have successfully running Docker on our Raspberry Pi!
NOTE: when using Docker on ARM CPU architectures you need a ARM based container image, otherwise you get EXEC errors because the base image has been build on a AMD/Intel machine.
However more and more images will have support for multiple architectures so you can run it on your desktop pc running Intel or AMD processors and your little Raspberry Pi.
That’s it.. happy Dockering!