Install Docker-Compose on Raspberry Pi

Install Docker-Compose on Raspberry Pi

Docker is a reputed open platform for building, deploying, running, and sharing containerized applications. A container is a loosely isolated environment.

As a result of the isolation and security, Docker makes it possible to deliver your software quickly and requires minimal resources.

Developers mostly prefer Docker as it speeds up the development process. The increased speed is because you can separate applications from infrastructure.

Docker-Compose is a tool for defining and running multi-container Docker applications.

In comparison to virtual machines, Docker containers are lightweight, which is vital if you are using a Raspberry Pi.

What is Raspberry Pi?

Raspberry Pi is the most popular tiny low-cost computer that was initially used for learning programming, but it was later used it to build a hardware and home automation projects. Furthermore, todays Raspberry Pi’s used widely in industrial applications.

In this tutorial, we show you the steps to follow to install Docker Compose on Raspberry Pi. Continue reading for more elaboration.

What you Need to Install Docker on Raspberry Pi
  1. Raspberry Pi with a running Raspbian OS
  2. SSH connection enabled
Steps to Install Docker Compose on Raspberry Pi;
  1. Set up your Raspberry Pi Operating System (OS)
  2. Upgrade Packages
  3. Install Docker
  4. Install Docker-Compose
  5. Enable the Docker system service to start your containers on boot
1. Setup your Raspberry Pi with Raspbian, WiFi, and SSH access

Skip this step if you have already set up your Raspberry Pi.

  • Download Pi Imager

The official Raspberry Pi Imager is an effortless means of installing OS on Raspberry Pi. The imager comes with the required tools to prepare and flash an SD card with the OS for installation.

Download and install the Pi Imager. If you are to run a headless install, you should select Raspberry Pi OS (32-bit) Lite. For the desktop version, use the ‘Full’ version.

  • Enable SSH Access

To make sure the SSH gets enabled when you start your Raspberry Pi, add empty file SSH to the root directory of the SD card after flashing it with the image.

If you are running the Raspberry Pi without a screen or keyboard, this step is essential. To link the Raspberry Pi to a Wifi network, ensure you avail the network details for the initial startup.

Define a wpa_supplicant.conf file in a similar root folder, and ensure it utilizes the line feed (LF) newline character.

Use the following default credentials to connect via SSH;

  • Username: pi
  • Password: Raspberry

touch ssh

  • Enable Wifi

Enable Wifi by creating a file called wpa_supplicant.conf in the root of the boot. Afterward, paste the following:

  • Eject the micro SD card
  • Boot the Raspberry Pi

After starting up the device, you can link it through SSH using its IP address. You can get this address from the router’s web interface.

Use:

ssh pi@[Raspberry Pi IP address]

Default username – pi

Standard password – Raspberry

You need to change the password during the first connection. You can also configure other valuable things in the handy Raspberry Pi Config Tool:

sudo raspi-config

2. Upgrading and Updating Systems

Update and upgrade the system to ensure you install the most recent version of the software. To do this, open a terminal window and run the following command;

sudo apt-get update

sudo apt-get upgrade

  • Assign the .local Domain to Your Raspberry Pi

Assign your Raspberry Pi a .local domain if you use it to host on your network. A .local domain enables you to access your Pi using a simple web address. With the .local domain, you don’t have to remember the IP address.

To create a .local domain, install Avahi Daemon on your Pi;

sudo apt-get install avahi-daemon

Once complete, you don’t need to reboot the device. Raspberry Pi will begin to recognize local network queries for its hostname. By default, the hostname is raspberrypi.

  • Install git

Install git as you will need it later.

sudo apt install git-

Upgrade Packages

  • Update your package list with the command:

Sudo apt update

  • Check installed packages to upgrade:

apt list –upgradable

  • Upgrade packages to latest version:

Sudo apt full-upgrade

3. Install Docker

You can install Docker using the convenience script offered at get.docker.com. 

  • Download and install Docker script 

To do this, run the command; curl -fsSL https://get.docker.com -o get-docker.sh

Whenever you download scripts from the internet, examine them before running locally.

  • Run the Docker install script

Execute installation script through;

Sudo sh get-docker.sh

4. Include a Non-Root Account to the Docker Group

Automatically, only root users or those with administrative privileges can run the containers. If you are logged out as the root, you can utilize the sudo prefix.

To execute docker commands and avoid typing the sudo each time, you can also add on-root users to the docker group.

The syntax to add more accounts to the Docker group is:

sudo usermod -aG docker ${USER}

To enhance the permissions to the existing user run:

sudo usermod -aG docker ${USER}

Check whether it’s running:

groups ${USER}

5. Log Out then Back In

If you run the command in (c) above, reboot Raspberry Pi for changes to get applied. Alternatively, you can run the command;

sudo su – ${USER}

6. Test Docker

To confirm that Docker installed correctly, take a look at the Docker version.

Run the command by typing;

docker version.

The output will show the Docker version and some extra information. If you’d like information about the whole system, that is, the kernel version, number of containers and images, and a more comprehensive description, type:

docker info

Alternatively, you can run the hello-world image. The best way to test whether the Docker setup is correct is to run the Hello World container.

You can do this by typing the command:

docker run hello-world

The software will get in touch with the Docker daemon, pull the “hello-world” image, and generate a new container depending on that image.

After completing all the steps, the output should let you know that your installation appears to be working correctly.

To remove the image:

docker image rm hello-world

7. Install Docker-Compose

You can install Docker Compose from pre-built binaries that you download from the release page for the project.

To install Docker-Compose, you’ll need to use pip3. Therefore, you need to install python 3 and pip3. If it’s not present, execute the following commands;

sudo apt-get install libffi-dev libssl-dev

sudo apt install python3-dev

sudo apt-get install -y python3 python3-pip

With pip3 and python3 installed, it’s possible to install Docker-Compose via the command;

sudo pip3 install docker-compose

8. Allow the Docker System Service to Launch your Containers on Boot

Since it’s a great and crucial addition, you can customize your Raspberry Pi to run the service with the Docker system automatically when it starts up.

Use the command

sudo systemctl to enable Docker

to run the Docker anytime it boots up. Containers with a relaunch policy set to unless-stopped or always automatically restart following a reboot.

Sample Docker Compose file

Here is an example of a Docker – Compose file that launches three containers. When started, the containers will come up automatically when the Raspberry Pi gets full power cycled.

Run this command to start the containers using Docker-Compose; docker-compose -f docker-compose.yaml up -d

Go to Docker Speed Test project  HYPERLINK “https://github.com/robinmanuelthiel/speedtest” on GitHub to learn more about this sample.

 

Raspberry Pi Docker Images

On Docker Hub, the number of ARM-compatible images is rising. As a result of the popularity of 64-bit ARM in some cloud providers, you may find it easy to get 64-bit Docker containers.

Raspberry Pi design is according to ARM architecture. For this reason, only some Docker images function on the Raspberry Pi.

All Docker image designs not intended for ARM devices will not function. Running docker-apps designed for x86/x64 and i386 architecture on your Raspberry Pi will result in an error.

When looking for images from Docker Hub, you can filter using operating systems and architectures to identify apps that are fully supported.

To customize solutions, the best option is to run a container based on an official image. You’ll then enhance it and apply the changes to a new image.

Upgrading Docker on Raspberry Pi

Rerunning the convenience script to upgrade Docker is not necessary. It can result in issues if it attempts to repositories that are already in place.

Utilize the package manager to upgrade Docker using the command:

sudo apt-get upgrade

Uninstalling Docker on Your Raspberry Pi

Despite having used a convenience script for installation, it’s possible to eliminate Docker through the package manager easily:

sudo apt-get purge docker-ce

Based on the software version, you’ll require an extra command to eliminate Docker:

sudo apt-get purge docker-ce-cli.

To delete images leftover, volumes, containers, and additional relative data, run this command:

sudo rm -rf /var/lib/docker

You’ll need to delete configuration files that are manually edited.

JFrog Connect is a modern Linux-first IoT platform designed to efficiently update, control and monitor edge and IoT devices at scale.