Pradeep Singh | 28th Jun 2017
Docker is now officially supported on Raspbian Jessie installation and you can easily install the Docker on your Raspberry Pi using just a single command. Let see how you can setup your Raspberry Pi and run your first container on it.
1. Install Raspbian:
If you already have a Raspberry Pi with Raspbian Jessie, you can skip this step. New users should install Raspbian OS on Raspberry Pi’s MicroSD card. For instructions, you can follow the OS installation guide on Raspberry Pi home page –
2. Update Packages:
Update Raspberry Pi packages using the following command –
sudo apt-get update && sudo apt-get upgrade
3. Install Docker:
Install Docker using following command –
curl -sSL https://get.docker.com | sh
4. Add permission to Pi User to run Docker Commands:
Add “pi” user to “docker” group using the following command –
sudo usermod -aG docker pi
You must Log off from Raspberry Pi and Login again, for this to take effect.
5. Verify Installation:
Check Docker installation using the “docker –version” command. If you see the correct version, you are good to go.
pi@RaPi1:~ $ docker --version Docker version 17.05.0-ce, build 89658be pi@RaPi1:~ $
6. Run Hello-World Program:
Run the ARM-based “hello-word” Docker container using “docker run armhf/hello-world” command. All the Docker Images under the namespace armhf are created by Docker team.
You can NOT run the default “hello-world” container (using “docker run hello-world” command) on Raspberry Pi as it is created for X86 Architecture and won’t work on ARM architecture based Raspberry Pi.
On successful execution, you should see following output on your Raspberry Pi –
pi@RaPi1:~ $ docker run armhf/hello-world Unable to find image 'armhf/hello-world:latest' locally latest: Pulling from armhf/hello-world a0691bf12e4e: Pull complete Digest: sha256:9701edc932223a66e49dd6c894a11db8c2cf4eccd1414f1ec105a623bf16b426 Status: Downloaded newer image for armhf/hello-world:latest Hello from Docker on armhf! 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. 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 Hub account: https://hub.docker.com For more examples and ideas, visit: https://docs.docker.com/engine/userguide/ pi@RaPi1:~ $
Congratulations!!! You have a working container on your Raspberry Pi.
Potential errors messages you may see:
1. If you see the following error, reboot your Raspberry Pi and try again –
docker: Error response from daemon: failed to create endpoint compassionate_joliot on network bridge: failed to add the host (veth0685c4b) <=> sandbox (vethccfe136) pair interfaces: operation not supported. ERRO error getting events from daemon: net/http: request canceled
2. If you see the following error, it means you are trying to run an X86 container on ARM machine i.e. Raspberry Pi. This is because the binary format used by ARM is not compatible with x86.
standard_init_linux.go:178: exec user process caused "exec format error"
After setting up your Raspberry Pi for Docker Containers, you should start creating your own Docker IoT Containers. The following article would explain how can you create your first Docker Container to Blink an LED connected to Raspberry Pi –
Raspberry Pi is a cost-effective solution to play with Docker Containers. If you have multiple Raspberry Pis, you can use them to create a Docker Swarm Cluster. Let me know about your IoT Applications you are running on Docker Containers, in the comments section.