How to Install Docker Compose in Linux?

By | December 18, 2021
How to Install Docker Compose in Linux

Docker Compose is one of the most popular tools provided by Docker among DevOps professionals. It allows you to run and manage multi-container applications using a single host and a single command line. You can run multiple services of your application in isolated environments and manage each of them using simple Docker Compose commands. Moreover, you can easily use Docker Compose in any stage of your development process which includes production, staging, development, testing, etc.

In this article, we will see how to install Docker Compose in Linux machines. Before you move ahead and install Docker Compose, please make sure that you meet the following prerequisites.

  1. You have a Linux machine with a Docker engine installed in it.
  2. You have access to sudo privileges or you are a user of the Docker group if you don’t want to run Docker commands using sudo.

So without any further ado, let’s get started.

Install Docker Compose in Linux

We can download the binary file for Docker Compose in the Linux machine from the following GitHub link. The latest stable version of Docker Compose is 1.29.0. We will use the curl command to download this release.

1. Let’s run the below curl command which will allow us to download the latest stable version 1.29.0 of Docker Compose.

Vamware
$ sudo curl -L "https://github.com/docker/compose/releases/download/1.29.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

2. Next, we need to give the binary file, permissions to execute.

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

3. In case the docker-compose command does not execute after installation, we need to make sure that the installation path is correct. Or we can simply create a symbolic link to the following path – /usr/bin

$ sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

4. After we have completed all these steps, we are now set to run our first Docker Compose command. Let’s try to verify the installation by checking the version.

$ docker-compose --version

Alternative Methods to install Docker Compose

In case you are not able to install Docker Compose using the above methods, there are two alternative methods that you can use. The first one is installing the Docker Compose tool using the pip command and the second one is installing it as a container.

Method 1:

We can easily install Docker Compose from the PyPI. However, it is recommended that if we opt for this method to install Docker Compose, we should create a virtual environment to do so because there are many conflicts between python system packages and the dependencies that Docker Compose requires.

To install Docker Compose using pip, we can use the following command.

$ pip install docker-compose

Method 2

The next alternative option is to install Docker Compose inside a container. We can do so using a simple bash script. To do so, we can use the following commands.

$ sudo curl -L --fail https://github.com/docker/compose/releases/download/1.29.0/run.sh -o /usr/local/bin/docker-compose

This will download the bash script from the GitHub link and move it to the target path.

Next, we need to provide execute permissions to this.

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

How to uninstall Docker Compose?

If you installed Docker Compose using the curl command, you can simply remove the docker-compose binary from the path using the following command.

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

If you had installed Docker Compose using the pip command, you can use pip uninstall command to remove it.

$ pip uninstall docker-compose

Wrapping Up!

To conclude, in this article, we discussed how to install Docker Compose in Linux. We discussed three different methods to do so.

  1. Using the curl command to download the binary.
  2. Installing from PyPI using pip command.
  3. Running Docker Compose inside a Container.

Finally, we also saw how we can uninstall Docker Compose in Linux. We certainly hope that with the help of this article, you will be able to get started with Docker Compose seamlessly.

Happy Learning!

People are also reading:

Leave a Reply

Your email address will not be published.