| by Arround The Web | No comments

How to Install Docker and Docker Compose on Raspberry Pi

Developing applications is a useful task that solves a wide range of problems; however, it can also be a complex and time taking task, especially when it comes to managing and deploying these applications on different platforms. With Docker and Docker Compose, the task has become a lot easier and you can quickly develop, deploy and manage applications.

In this guide, you will learn about:

What is Docker and Docker Compose

Docker is an effective platform that allows you to develop, deploy and run applications, it does this by containerizing applications. Containers on the other hand are isolated environments that package up an application code, runtime, system tools and system libraries required to run an application. Thus, making it easy to move applications on different platforms without worrying about any compatibility issue. On the other hand, Docker Compose is a tool used to run multi-containers Docker applications, and it allows you to define your application services and their dependencies in a yaml file.

Why We Need Docker and Docker Compose

Having a Docker and Docker Compose installed on the system will make it easier to deploy, develop and run applications. They are popular choices for developing and deploying web applications, or running machine learning based models. With Docker and Docker Compose, a developer can easily create a containerized development environment having all the tools and dependencies required to run an application. Multiple containers can easily be deployed on a single command, thus save developers time in running multiple commands. They can also become useful to create a containerized environment specially to run machine-learning models.

Why Docker and Docker Compose is Useful for Raspberry Pi

Docker and Docker Compose is a useful choice for Raspberry Pi since the applications developed from Docker are cost effective and efficient. They are also lightweight, thus consuming less Raspberry Pi CPU resources. Besides that, Docker and Docker Compose are well suited for developing and deploying applications on Raspberry Pi since they are open source and can be freely used.

Prerequisites Required for Installing Docker and Docker Compose on Raspberry Pi

For installing Docker and Docker Compose on Raspberry Pi, you will need to have following prerequisites:

  • Raspberry Pi 3, 4 or 5 with at least 2GB RAM
  • Raspberry Pi Operating System
  • Complete Desktop Setup
  • A user account with sudo privilege

How to Install Docker and Docker Compose on Raspberry

For installing Docker and Docker Compose on Raspberry Pi, you can use:

  • apt Package Manager
  • Deb Package
  • Script
  • Snap Store

How to Install Docker and Docker Compose on Raspberry from apt Package Manager

The apt package manager is a straightforward method for installing Docker and Docker Compose on Raspberry Pi. It retrieves the package from the system official repository. You can use the following steps to complete the installation of Docker and Docker Compose on Raspberry Pi from the apt package manager:

Step 1: Update and Upgrade Raspberry Pi Packages

Since we are installing Docker and Docker Compose from Raspberry Pi official repository, you should update and upgrade the packages currently installed on your system via following command:

sudo apt update && sudo apt upgrade -y

Step 2: Install Docker and Docker Compose from Raspberry Pi Repository

After upgrading the packages, you can install Docker and Docker Compose on Raspberry Pi from the following command:

sudo apt install docker.io docker-compose -y

Step 3: Check Docker Version on Raspberry Pi

After completing the Docker installation, run the following command to check it is installed successfully on the Raspberry Pi system:

docker --version

Step 4: Check Docker Compose Version on Raspberry Pi

You can also use the following command to check Docker Compose is successfully installed on your Raspberry Pi system:

docker-compose version

How to Remove Docker and Docker Compose on Raspberry from apt Package Manager

The Docker and Docker Compose installed from apt package manager isn’t the updated version; thus, if you want to remove it from Raspberry Pi, you can use the following command:

sudo apt remove docker.io docker-compose -y

How to Install Docker and Docker Compose on Raspberry Pi from Deb Package

Since Raspberry Pi is a Debian based system, you can also download a Deb package for Docker on Raspberry Pi. However, you won’t be able to download and install Docker Compose deb file. To install Docker on Raspberry from Deb package, you can use the following steps:

Step 1: Download Deb Package for Docker on Raspberry Pi

First, download the Deb package for Docker on Raspberry Pi according to your system (either armv7 or arm64). If you are using the Raspberry Pi 32 Bit version, download armv7, while for 64 Bit version, go with arm64. Here, I am using 64 Bit Raspberry Pi OS, thus I am going with arm64.

To download the arm64 version of Docker on Raspberry Pi, you can use the following command:

wget https://download.docker.com/linux/debian/dists/bullseye/pool/stable/arm64/docker-ce_24.0.6-1~debian.11~bullseye_arm64.deb

Note: You can download the Docker version according to your system from here.

Step 2: Install Docker from Deb Package

To install Docker from the Deb package on Raspberry Pi, you can use the apt package manager by running the following command:

sudo apt install ./docker-ce_24.0.6-1~debian.11~bullseye_arm64.deb -y

Step 3: Check Docker Version on Raspberry Pi

To check whether the Docker version is successfully installed on Raspberry Pi from this method, you can use the following command:

docker --version

How to Remove Docker and Docker Compose on Raspberry Pi from Deb Package

You can remove Docker installed from Raspberry Pi through the Deb package by simply running the following command:

sudo apt remove docker-ce -y

How to Install Docker and Docker Compose on Raspberry from Script

If you want to install only Docker on Raspberry Pi, you can use the installation script to successfully install it on your system. For installing Docker Compose, you have to look for other options presented in this guide. To install Docker on Raspberry Pi from script, use the following steps:

Step 1: Download Docker Executable Script

First, run the following command to download the executable script on Raspberry Pi:

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

Step 2: Run the Script on Raspberry Pi

Now, run the Docker Script using the following command on Raspberry Pi:

sudo sh get-docker.sh

Step 3: Check the Docker Version

You can confirm the Docker version installed from the script by using the following command:

docker --version

How to Remove Docker and Docker Compose on Raspberry from Script

Since we have downloaded only Docker from the script, we can remove it from the Raspberry pi source directory by first finding where it is installed on the system. This can be done if you run the following command:

which docker

Then execute the command provided below to remove Docker installed on Raspberry Pi:

sudo rm -rf /usr/local/bin/docker

How to Install Docker and Docker Compose from Snap Store

Snap is a package installation store for Linux and Debian based systems that can also be used to install Docker. However, you won’t be able to install Docker Compose through this method since it is not available in the Snap Repository. To install Docker on Raspberry Pi from Snap Store, use the steps below:

Step 1: Install Snap Store on Raspberry Pi

By default, Snap Store isn’t installed on Raspberry Pi, however, you can install it from the apt package manager using the command given below:

sudo apt install snapd -y

Step 2: Install Core from Snap Store

You should also install core from the Snap Store to keep installing the latest version of the software, this can be done via the command given below:

sudo snap install core

Step 3: Install Docker from Snap Store

After installing both Snap Store and Core, you can now install Docker on Raspberry Pi from the following command:

sudo snap install docker

Note: You must restart the terminal or reboot the system to ensure successful installation of Docker on Raspberry Pi from Snap Store.

Step 4: Check Docker Version on Raspberry Pi

You can check the Docker version on Raspberry Pi installed from Snap Store by using the following command:

docker --version

How to Remove Docker and Docker Compose on Raspberry Pi from Snap Store

In case you want to remove Docker from the Snap Store from Raspberry Pi, you can use the following command:

sudo snap remove docker

How to Use Docker and Docker Compose on Raspberry Pi

Before using Docker and Docker Compose on Raspberry Pi, ensure both are successfully installed from any of the above methods. After that, you can use the following steps to run a container using Docker and Docker Compose on Raspberry Pi:

Step 1: Create a Hello World Directory

First, create a hello-world directory on your Raspberry Pi system from the following command:

mkdir hello-world

Step 2: Navigate to Hello World Directory

Now, navigate to the hello-world directory from the following command:

cd hello-world

Step 3: Create a Yml File

Then, create a yml file on the Raspberry Pi system from the following command as this file will be used to configure your docker application services:

nano docker-compose.yml

Inside the file, add the following test code.

my-test:

image: hello-world

The first line of the file is used as a part of the container name, while the second line tells which image is used to create a container on Raspberry Pi.

Note: Save the file using CTRL+X, add Y and Enter to exit.

Step 4: Check Images in Docker

If you want to manually look at the created images in Docker, you can use the following command:

docker images

Step 5: Pull the Image from Docker Hub Repository

Since the above steps successfully created the image, you can pull this image from Docker Hub repository using the following command:

sudo docker-compose up

Once you pull the image from the docker-compose, it creates a container, attaches and runs a hello-world program, ensuring the successful working of the Docker and Docker Compose on Raspberry Pi.

Step 6: Remove Image from Docker

In case you want to remove the image from Docker, you have to first get the container ID of the image using the following command:

docker ps -a

Then run the following command to remove Docker container ID:

docker rm <CONTAINER ID>

After that, use the following command to remove Docker image:

docker rmi hello-world

Conclusion

Docker and Docker Compose can be installed on Raspberry Pi from the apt package manager, deb package, installation script or Snap Store. This guide has provided a detailed step-by-step guide to install Docker and Docker Compose through these aforementioned methods. You will also find the methods to remove the Docker and Docker Compose from Raspberry Pi in case you no longer need them.

Share Button

Source: linuxhint.com

Leave a Reply