As part of one of my recent experiments I wanted to install docker on my raspberry pi. The procedure nowadays seems significantly better than a couple of years ago when I first tried. However, there are always some little details that can be a bit frustrating when following steps.
Although the process to install docker is well described in their website, it's focused on Debian distribution. We all know that Raspbian is based on Debian and therefore most of the instructions for will apply without much trouble.
That said, I will detail the exact steps I followed to get docker installed on my raspberry pi, this procedure was tested on 3B, Zero and Zero W.
First, update the package list, if you haven't done yet after setting up your raspberry pi.
$ sudo apt-get update
Install packages to allow apt to use a repository over HTTPS.
$ sudo apt-get install \ apt-transport-https \ ca-certificates \ curl \ gnupg2 \ software-properties-common
Add Docker’s official GPG key. Note that here the url points to raspbian directory and not to debian as per the original instructions.
curl -fsSL https://download.docker.com/linux/raspbian/gpg | sudo apt-key add -
The next step recommended didn't work for me.
sudo add-apt-repository \ "deb [arch=armhf] https://download.docker.com/linux/raspbian \ $(lsb_release -cs) \ stable"
It failed with an error similar to this:
Traceback (most recent call last): File "/usr/bin/add-apt-repository", line 95, insp = SoftwareProperties(options=options) File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py" , line 109, in __init__ self.reload_sourceslist() File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py" , line 599, in reload_sourceslist self.distro.get_sources(self.sourceslist) File "/usr/lib/python3/dist-packages/aptsources/distro.py", line 89, in get_sources (self.id, self.codename)) aptsources.distro.NoDistroTemplateException: Error: could not find a distribution template for Raspbian/stretch
Instead, I tried this other way, more explicitly setting up the repository into a new docker.list sources file.
$echo "deb [arch=armhf] https://download.docker.com/linux/raspbian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list
With the new source repository in the list, update the package list again.
$ sudo apt-get update
Now we are in a position to install docker-ce from the repository, in this particular case, I ran into an issue with the latest version, documented in github basically they suggest to go back to 18.06.1 which we can get from the command below as per official docker instructions on how to get a specific version.
$ apt-cache madison docker-ce docker-ce | 5:18.09.0~3-0~raspbian-stretch | https://download.docker.com/linux/raspbian stretch/stable armhf Packages docker-ce | 18.06.2~ce~3-0~raspbian | https://download.docker.com/linux/raspbian stretch/stable armhf Packages docker-ce | 18.06.1~ce~3-0~raspbian | https://download.docker.com/linux/raspbian stretch/stable armhf Packages docker-ce | 18.06.0~ce~3-0~raspbian | https://download.docker.com/linux/raspbian stretch/stable armhf Packages
As of this writing, the version I tried is 18.06.2~ce~3-0~raspbian, which can be installed using the apt-get command.
$ sudo apt-get install docker-ce=18.06.2~ce~3-0~raspbian containerd.io
Also notice that by using this vesion, there's no need to install docker-ce-cli.
Testing everything is running as expected.
$ sudo docker info Containers: 0 Running: 0 Paused: 0 Stopped: 0 Images: 1 Server Version: 18.06.2-ce --- more data ---
Run the hello world. Usually we get the command sudo docker run hello-world but that only works on "normal" architectures, in this case, we're using ARMv6/7, but to make it more compatible with all of them, I ran the image from arm32v5/hello-world.
$ sudo docker run arm32v5/hello-world Unable to find image 'arm32v5/hello-world:latest' locally latest: Pulling from arm32v5/hello-world 590e13f69e4a: Pull complete Digest: sha256:8a6a26a494c03e91381161abe924a39a2ff72de13189edcc2ed1695e6be12a5f Status: Downloaded newer image for arm32v5/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. (arm32v5) 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/
And that's all, docker installed up and running on a raspberry pi.
UPDATE:
If you'd like to get rid of the sudo command every time you use docker, then you can run the following command found in the official guide as a post-installation step. You don't need to create the group as it's already created by docker installation. It adds your user to the docker group.
$ sudo usermod -aG docker $USER
You need to log out and back in for this change to take effect. After that you'll be able to run all docker commands as a regular user.