How to Install Docker Compose on Ubuntu

Install Docker Compose Ubuntu

If you're looking to streamline your application deployment process with Docker, then Docker Compose is the tool for you. Docker Compose is a command-line tool that allows you to define, configure, and manage multi-container Docker applications. In this article, we'll guide you through the process of installing Docker Compose on Ubuntu and getting started with containerizing your applications.

Installing Docker Compose on Ubuntu

To begin, make sure you have Docker installed on your Ubuntu machine. If you haven't installed Docker yet, you can check out our article on How to Install Docker on Ubuntu for step-by-step instructions.

Once you have Docker installed, you can proceed with the installation of Docker Compose. Follow the steps below:

  1. Start by updating your package index:
$ sudo apt update
  1. Install the necessary dependencies:
$ sudo apt install curl
  1. Download the latest version of Docker Compose using the following curl command. Replace <compose-version> with the actual version number you wish to install:
$ curl -sSL https://github.com/docker/compose/releases/download/<compose-version>/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
  1. Make the downloaded file executable:
$ sudo chmod +x /usr/local/bin/docker-compose
  1. Verify the installation by checking the version of Docker Compose:
$ docker-compose --version

If Docker Compose has been successfully installed, you will see the version number displayed on your terminal.

Now that you have Docker Compose up and running on your Ubuntu machine, you can start leveraging its powerful functionality to manage your Docker applications efficiently.

Create a Docker Compose file

To define and configure your multi-container Docker application, you need to create a Docker Compose file. The Docker Compose file, typically named docker-compose.yml, is written in YAML format and consists of a set of services that make up your application. Each service is defined with its own configuration, including the base image, ports, environment variables, and more.

Here's an example of a simple Docker Compose file:

version: '3'
services:
  web:
    image: nginx:latest
    ports:
      - 80:80
    volumes:
      - ./html:/usr/share/nginx/html

In this example, we define a service called "web" based on the official NGINX image. It exposes port 80 and mounts the html directory from the current working directory to the NGINX container's /usr/share/nginx/html directory. This way, any changes you make to the local html directory will be reflected in the NGINX container.

Running Docker Compose

To run your Docker Compose file, navigate to the directory where the file is located and use the following command:

$ docker-compose up

This command starts all the services defined in your Docker Compose file. You will see the output of each service displayed in your terminal. If you want to run the services in detached mode (in the background), you can use the -d flag:

$ docker-compose up -d

To stop and remove all the containers created by Docker Compose, use the following command:

$ docker-compose down

Conclusion

In this article, we have walked you through the process of installing Docker Compose on Ubuntu. With Docker Compose, you can easily manage your multi-container Docker applications and simplify your application deployment workflow. Now that you have a basic understanding of Docker Compose, you can explore more advanced features and configurations to truly unleash the power of containerization.

For more information on Docker and other related topics, check out the following articles:

Start experimenting with Docker Compose and revolutionize your application development and deployment process. Happy containerizing!

Ruslan Osipov
Written by author: Ruslan Osipov