The Ultimate Guide to Installing Docker Compose on Raspberry Pi
Learn how to install and use Docker Compose on your Raspberry Pi to deploy containerized applications and simplify your workflow. …
Updated September 21, 2023
Learn how to install and use Docker Compose on your Raspberry Pi to deploy containerized applications and simplify your workflow.
Introduction
Docker is an open-source platform that helps developers create, deploy, and run applications using containers. It’s a popular choice for simplifying application development and deployment processes by allowing developers to package all dependencies into a single container. Docker Compose is a tool that allows you to define and run multi-container Docker applications with ease. In this article, we’ll show you how to install Docker Compose on Raspberry Pi and get started with your first Docker Compose project.
Prerequisites
Before we begin, make sure you have the following:
- A Raspberry Pi device with the latest Raspbian OS installed.
- Basic knowledge of Docker and its concepts (containers, images, etc.).
- SSH access to your Raspberry Pi, either through a terminal or using an SSH client like PuTTY.
Step 1: Install Docker on Raspberry Pi
Docker Compose depends on the Docker Engine, so you need to install it first. Follow these steps to install Docker on your Raspberry Pi:
- Update your package lists and install dependencies:
sudo apt-get update sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
- Add the official Docker GPG key to your system:
curl -fsSL https://download.docker.com/linux/raspbian/gpg | sudo apt-key add -
- Add the Docker repository to your package sources:
sudo add-apt-repository "deb [arch=armhf] https://download.docker.com/linux/raspbian $(lsb_release -cs) stable"
- Update your package lists again and install Docker:
sudo apt-get update sudo apt-get install -y docker-ce
- Verify that Docker is installed correctly by running the
hello-world
image:sudo docker run hello-world
If everything goes well, you should see a message indicating that your installation was successful.
Step 2: Install Docker Compose
Docker Compose can be installed using the official Python package docker-compose
. Follow these steps to install it on your Raspberry Pi:
- Install
pip
, a Python package manager, if you don’t have it already:sudo apt-get install -y python3-pip
- Upgrade
pip
andsetuptools
:sudo pip3 install --upgrade pip setuptools
- Install Docker Compose using
pip
:sudo pip3 install docker-compose
- Verify that the installation was successful by running:
docker-compose version
You should see the Docker Compose version and the Docker Engine version.
Step 3: Create a Docker Compose Project
Now that you have Docker and Docker Compose installed, let’s create a simple project to get started. We’ll use the official Nginx image as an example.
- Create a new directory for your project:
mkdir my-nginx-project cd my-nginx-project
- Create a
docker-compose.yml
file in the project directory with the following content:version: '3' services: web: image: nginx:latest ports: - "80:80"
This configuration defines a single service called
web
that runs the latest Nginx image and exposes port 80. - Start your Docker Compose project by running:
docker-compose up -d
- Check if Nginx is running by visiting your Raspberry Pi’s IP address in a web browser or using
curl
:curl http://<raspberry_pi_ip>
You should see the default Nginx welcome page.
Step 4: Manage Your Docker Compose Project
Docker Compose provides several commands to manage your projects, such as starting, stopping, and scaling containers. Here are some common ones:
docker-compose up -d
: Start your project in detached mode (in the background).docker-compose down
: Stop and remove all containers, networks, and volumes created by your project.docker-compose ps
: List all running containers for your project.docker-compose logs
: View output from your containers.docker-compose scale web=3
: Scale theweb
service to 3 instances.
Conclusion
In this article, we learned how to install Docker and Docker Compose on Raspberry Pi and created a simple project using Nginx. You can now use Docker Compose to deploy more complex applications with multiple containers and easily manage them. With its powerful features, Docker Compose is a must-have tool for any modern software development workflow.