Installing Docker on Raspberry Pi| Raspberry PI home server series | Article 1

This is the first article in the Raspberry PI home server series. Check out other articles in this series.

Astitva Sood
3 min readJul 3, 2021
  1. Installing Docker on Raspberry Pi.
  2. Setting up static IP on Raspberry Pi.

Docker is an open platform for developing, shipping, and running applications. The main feature is that docker containers are lightweight and run on minimal resources, a point very valuable if you are trying to run docker on raspberry pi.

Raspbian supports docker by default. In this article, you will get a step-by-step guide on how to install and run Docker on Raspberry pi.

Tested on raspberry pi 4 running on Raspberry Pi OS on 3 July, 2021

Prerequisites:

  1. Raspberry Pi running on Raspbian OS
  2. Internet connection on Raspberry Pi
  3. SSH connectivity to raspberry PI

Steps:

  1. System update and upgrade
  2. Download docker install script
  3. Installing docker
  4. Enabling non-root users to run docker commands
  5. Verifying Install
  6. Creating a hello world container
  7. Downloading and installing docker-compose

1. System update and upgrade

Open the terminal and run the following command-

sudo apt-get update && sudo apt-get upgrade

This will update the apt repositories and upgrades the installed packages with the latest version.

2. Downloading docker install script

curl -fsSL https://get.docker.com -o ~/docker-install.sh

This will download the docker install script and save it in the docker-install.sh file in the user's home directory.

3. Installing docker

Now that the install script is downloaded, just run the script as root user by the following command:

sh ~/docker-install.sh

4. Enabling non-root users to run docker commands (optional)

By default, you need root privileges to run docker commands. However, you can grant access to non-root users to run the commands as well. Just run the following command.

sudo usermod -aG docker [user_name]

If you don't know your user name, you can get it by running the following command

whoami

Note it is important to reboot the raspberry pi for this to take effect

This can be done by the following command

sudo reboot

5. Verifying Install

To verify everything is installed correctly, run the following commands

docekr versiondocker info

6. Running hello-world container

Run a hello-world container to confirm the successful install. This command will download the imager from the docker hub and run the container.

docker run hello-world

Bonus!

Docker cheat sheet

docker ps                          // list running docker containersdocker images                      // get list of local imagesdocker logs -f <container_id>     // get container logsdocker rmi <image>                // delete imagedocker exec -it <container_id> bash // get bash shell in container

--

--