In case you aren’t familiar with Docker; Docker is a powerful PaaS (Platform as a Service) tool that provides OS-level virtualization to deliver software in packages called “Containers”. Containers are isolated from one another and hold their own software, tools, libraries and configuration. However they can communicate with each other though well-defined channels as all of the containers share the same OS Kernel.
As all of the containers use the same OS kernel, they use fewer resources compared with virtual machines. During my Azure Administrator training the labs were also containerized using Docker. Docker can run on any OS such as Windows, Linux, macOS but also on Raspberry Pi and that’s our focus for today.
Since Docker containers are lightweight, they’re perfect to run on your RPi and allow you to run multiple containers while maintaining a very low overhead. Just to give you an example; I have 14 containers running and my average CPU load is around 8%!
How to install Docker?
It’s very easy to install Docker on your Raspberry Pi. Simply follow the steps below.
- Log on your RPi using SSH
- Update & Upgrade your current environment using the below commands. Note that this might take a few seconds.
sudo apt update sudo apt upgrade
- With the command below you will pipe the script directly into the command line. This script can take a few moments to run and it’ll automatically detects and installs everything it needs to run Docker on your Raspberry Pi.
NOTE: Always double check the source before piping scripts! In order to view the source you simply can copy the url and inspect it before running. In this case I’ve done this already so I know it’s from a legitimate source.
curl -sSL https://get.docker.com | sh
- In order to use Docker we need to make sure that our user has actually access to Docker and it’s containers. In my case my username is “pi” and it needs to be added in the same group as Docker using the below command. The reason for doing so is that otherwise we would be needing to run as root user in order to “talk” with Docker.
sudo usermod -aG docker pi
- The above change will only take effect after you logout
- Log back in and run the below command. You’ll see that docker is listed in the groups where the current user is part of.
Run your first Docker
This is the part where we get to test if we have set-up Docker correctly. Simply run the the “Hello World” container:
docker run hello-world
and you’ll be greeted with the below message.
Hello from Docker! This message shows that your installation appears to be working correctly.
This shows you that everything have been installed correctly and that you have set-up your Docker just fine. Meaning that you’re ready to install more Dockers on your Raspberry Pi. Next post will be about Portainer and how we can use this to maintain our Dockers in a very easy way!