Docker is a service that provides OS-level virtualization in the form of containers. These containers serve as a management tool for application development and communication between containers. It is essential to learn how to install Docker Compose on Debian 10.
In this article, you will learn how to install Docker Compose on Debian 10.
Before we start with the Docker installation, it is essential to learn about the edition of Docker. There are two versions available on the Docker website:
Community Edition (CE): It is suitable for developers and small teams looking to learn and implement Docker.
Enterprise Edition (EE): The Enterprise Edition is ideal for enterprise development and IT teams responsible for building, shipping, and running business-critical applications.
When we talk about Docker, it is crucial to understand its widely used terminologies in the ecosystem. The terminologies are:
Daemon: Also known as Docker Engine, it is a background process that runs on the host machine
Client: A command-line tool used by the client to interact with the Docker Engine.
Image: An image is a snapshot of a container. It consists of a file system and dependencies required to run an application.
Docker container: A running instance of a docker image with an application and its dependencies inside the container. Each container possesses a unique process ID and is isolated from other containers.
Docker registry: This is a scalable, server-side application responsible for storing and delivering Docker images. It can be private or public.
For this tutorial, you will need a host machine with Debian 10 installed and configured. You will also require a sudo account with privileges.
Install Docker on Debian 10
To start with Docker Compose, there are several steps you must perform to ensure the successful installation of Docker Compose. So, let’s get started with the tutorial.
1. Uninstall Default Docker Packages
Firstly, remove all the old and default versions of docker, docer.io, and engine from the host machine. Use the following command to perform this step:
sudo apt-get purge docker lxc-docker docker-engine docker.io
2. Install Required Packages
Secondly, update your system and default repository packages using the apt-get command. For example:
sudo apt-get update
Next, download the following dependencies required for the Docker Compose. These include HTTP certificates and the Curl package.
sudo apt-get install apt-transport-https ca-certificates curl gnupg2 software-properties-common
3. Install Docker
There are several ways to install Docker since Docker is available for different systems. The most practical approach is to set up its repository and install the software. Alternatively, for users with Debian systems, they can download the DEB package and install it manually. However, if you have Raspbian, you can set up Docker using the automated convenience scripts. We will discuss the first method in detail.
To start with the installation, download Docker’s official GPG key using the CURL command. For example:
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
Next, add the Docker repository to the system repository using the add-apt command.
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian buster stable"
You will get a similar output as shown below:
After that, update the apt repository:
sudo apt-get update
Next, Install Docker Engine. For our tutorial, we are installing Community Edition. Install it using the apt-get install command
sudo apt-get install docker-ce docker-ce-cli containerd.io
After the successful installation, the service will start automatically. To check its status, use the status command. For example:
sudo systemctl status docker
You will get a similar output.
Lastly, you can verify the Docker version by using the following command:
4. Verify the Installation
In this step, you will verify the Docker installation by running a default Docker image. The default Docker image you will use is a hello-world test image. To download it from Docker, run the following command:
docker run hello-world
Not only does this command automatically download the image, but it also creates a container for that image.
To run this Docker image, use the run command followed by the container name. For example:
5. Install Docker Compose on Debian
Now that your Docker container is up and running, you will install the current stable version of Docker Compose using the following command:
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
Make sure to replace the version number with the latest version.
Next, Allow execution permissions to the binary that you have downloaded.
sudo chmod +x /usr/local/bin/docker-compose
After that, check the Docker Compose version:
6. Test Docker Compose on Debian 11
To test Docker Compose, create a project folder using the mkdir command. For example:
Navigate to the project folder using the cd command.
Now, create a Docker Compose YAML file using vim or nano command.
After that, you will instruct Docker to create a container based on the hello-world image you downloaded in Step 5. Add the following configurations in the YAML file.
Save changes and exit the editor.
Let’s look at the code first.
The “Version” keyword specifies the Compose file version. The “Services” keyword lists the services that would separately run in each container. Right now, we only have one service. You can add multiple services in the list, followed by a comma. Lastly, we have linked the container in the “Image” keyword.
Lastly, you will launch the container using the following command:
sudo docker-compose up -d
7. Stop Docker Compose
To stop the running container in Docker Compose, use the stop command. For example:
To remove containers from Docker Compose, run the rm command as shown below:
In this tutorial, you have learned how to install Docker and Docker Compose on Debian 10 to run multiple containers. We have also covered how to run test images in Docker Compose. You can now start learning the advanced functionality of Docker Compose from its official documentation. For a different Linux flavor, check out Docker Installation on Ubuntu.
If this guide helped you, please share it.