Debian

How to Install Docker Compose on Debian 12 Bookworm

Docker is a powerful containerization tool that enables you to package and run applications in an isolated environment known as a container. When you have multiple applications consisting of multiple interdependent services, managing and coordinating their containers can become a complex task. In that case, you will need docker compose which allows you to manage and coordinate the multi-container applications. It leverages the YAML file that provides instructions for each container’s configuration. These configurations include the container’s ports, variables, images, environment and their dependencies.

In this guide, you will learn:

How to Install Docker Compose on Debian 12

How to Use Docker Compose on Debian 12

Conclusion

How to Install Docker Compose on Debian 12

You can install docker compose on Debian 12:

How to Install Docker Compose on Debian 12 from Default Repository

You can install docker compose on Debian 12 from the default system repository using the following steps:

Step 1: Update Debian 12 Repository

Before installing docker compose, update the Debian 12 repository using the below-provided command:

sudo apt update && sudo apt upgrade -y

Step 2: Install Docker Compose on Debian 12

After updating the repository, use the below-given command to install docker compose on Debian:

sudo apt install docker-compose -y

Step 3: Check Docker Compose Version on Debian

To confirm docker compose is installed on Debian 12, you can run the following command. It will provide you with the version that ensures docker compose is successfully installed on your system:

docker-compose --version

How to Remove Docker Compose from Debian 12

If you have installed docker compose from Debian repository, you can remove it from your system anytime using the following command:

sudo apt remove docker-compose -y

How to Install Docker Compose on Debian 12 from Docker Compose Executable File

The default repository method used for installing docker compose on Debian 12 will not install the latest version of the software. However, you can download the latest version docker compose executable file and perform the required steps to install docker compose on Debian 12. The complete step-by-step instructions to install docker compose on Debian 12 from docker compose executable file are given below:

Step 1: Download Docker Compose Executable File

First, download the latest version of docker compose file from the GitHub release page based on the system you are using.

If you are using Debian 12 amd64 operating system, you can simply run the below-given command in the terminal:

sudo wget https://github.com/docker/compose/releases/download/v2.23.3/docker-compose-linux-x86_64

The above command will download the docker compose file on Debian 12.

Step 2: Rename Docker Compose File

Now rename the docker-compose-linux-version file that you downloaded in the early step with docker-compose from the below-given command:

sudo mv docker-compose-linux-x86_64 docker-compose

Step 3: Copy the Docker Compose File to Bin Directory

Then copy the docker-compose file to bin directory from the following command:

sudo cp docker-compose /usr/local/bin

Step 4: Make the Docker Compose File Executable

After that, make the docker compose file executable on Debian 12 with the chmod command given below:

sudo chmod +x /usr/local/bin/docker-compose

Step 5: Set Path Variable

You must also set the path variable for docker compose directory so that the system will know the location of the docker-compose file. To set the path variable on Debian 12, open the .bashrc file from the command given below:

sudo nano ~/.bashrc

Then add the following line inside the .bashrc file:

export PATH="$PATH:/usr/local/bin/docker-compose"

Note: You can find the location of docker-compose file using the following command:

which docker-compose

You must save the .bashrc file using CTRL+X, add Y and press Enter, then use the source command given below to reload the changes to the .bashrc file:

source ~/.bashrc

Step 6: Check Docker Version on Debian 12

To confirm the installation and ensure the latest version of docker compose is installed on Debian 12, you can use the following command:

docker-compose --version

Note: You can remove docker compose on Debian 12 installed from the above method by removing the source directory using the following command:

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

Bonus Method: How to Install Docker Compose on Debian 12 from Docker Desktop App

Docker Desktop is a GUI based application that allows you to manage docker-related activities on your system. If you want to install the docker and docker compose latest release on Debian 12, you can go for installing Docker Desktop. However, Docker Desktop will not run if you are using Debian as a virtual machine because it doesn’t support nested virtualization.

How to Use Docker Compose on Debian 12

To learn how to use docker compose on Debian 12, you must ensure both docker and docker compose are installed on your system. After that, follow the below-given steps to lean the use of docker compose on Debian 12:

Step 1: Create a Hello World Directory

First, create a hello-world directory on Debian 12 using the following command:

mkdir hello-world

Step 2: Navigate to Hello World Directory

Then use the cd command to open the hello-world directory on the terminal:

cd hello-world

Step 3: Create an yml File

You should also create an yml file that you will use later on for configuring the docker application services, this file can be created in Debian 12 using:

nano docker-compose.yml

Inside this file, add the code given below:

my-test:

image: hello-world

You can then save the file using CTRL+X, add Y and press Enter to exit:

Step 4: Pull the Docker Image

After creating the image on Debian, you can pull it from the docker hub repository using the following command:

sudo docker-compose up

In this way, you can work with docker compose on your Debian system.

Conclusion

Docker Compose is a powerful tool used for managing multiple container applications. You can install docker compose on Debian 12 from the default system repository or through the docker compose executable file. The repository method installs the old version of docker compose while the executable file method will install the latest version of docker compose on Debian 12. The complete process with a step-by-step guide to install docker compose on Debian 12 using both these methods are provided in the above sections of this guide. Follow them and start working with docker and docker compose your Debian system.

About the author

Awais Khan

I'm an Engineer and an academic researcher by profession. My interest for Raspberry Pi, embedded systems and blogging has brought me here to share my knowledge with others.