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.
- Installing Docker on Raspberry Pi.
- 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:
- Raspberry Pi running on Raspbian OS
- Internet connection on Raspberry Pi
- SSH connectivity to raspberry PI
Steps:
- System update and upgrade
- Download docker install script
- Installing docker
- Enabling non-root users to run docker commands
- Verifying Install
- Creating a hello world container
- 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