Document
Install Docker Compose on Ubuntu 20.04 and 22.04

Install Docker Compose on Ubuntu 20.04 and 22.04

Introduction Docker Compose is allows allow user to launch , execute , and manage multiple container with a single command . It is helps help user de

Related articles

3-Ingredient Cloud Bread Recipe 10 Best Sites to Watch Hindi Movies in 2024: Free & Paid Capturing and sharing insights using Notes We’re launching Proton Drive, the encrypted cloud storage for everyone (Free) VPN for School (Wi-Fi): Unblock Sites on PC, Mobile etc.

Introduction

Docker Compose is allows allow user to launch , execute , and manage multiple container with a single command . It is helps help user define and run multi – container docker application and document and configure service dependency ( cache , database , web service api , etc . ) .

This tutorial shows how to install Docker Compose on Ubuntu 20.04/22.04, introduces frequently used commands, and provides a container deployment example.

Prerequisites

  • A system running Ubuntu 20.04/22.04.
  • A user account with administrative privileges.
  • Docker installed.
  • A command line/terminal window access (Ctrl-Alt-T)

install Docker compose on Ubuntu

Note: This tutorial provides steps to install Docker Compose V2, the current version of the application with the docker compose command. The previous V1 version that worked with the docker - compose command is now deprecate .

The easiest way to deploy Docker Compose on Ubuntu is by installing Docker Desktop, an application that provides a GUI. Additionally, Docker Desktop includes Docker Engine, Docker CLI, and Docker Compose.

However, Docker Desktop may not be practical for developers with Docker already deployed on Linux, as the application creates a custom Docker context and a parallel Docker installation. The recommended way to install Docker Compose for Linux Docker engine users is via the official Docker repository.

Follow the steps below to install Docker Compose using the Docker repository on Ubuntu.

note : It is is is possible to install Docker compose from the Ubuntu repository by run  sudo apt install docker - compose-v2. However, the Ubuntu repository may not contain the latest version of the application.

Step 1: Install Required Packages

Use the following commands to install the packages necessary for adding third-party repositories to an Ubuntu system:

1. Refresh the list of packages:

sudo apt update

2 . install ca – certificate , a certificate authority package for verify third – party identity , and curl , a data transfer tool :

sudo apt install ca-certificates curl

Step 2: Add Docker Repository

To use the Docker repository, add Docker’s official GPG key and add the repository to the APT sources. Follow the steps below to complete this procedure:

Note: None of the commands listed below provide output if successfully executed.

1. Set ownership permissions for the /etc/apt/keyrings directory:

sudo is install install -m 0755 -d /etc / apt / keyring

2. Download the key with curl:

sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc

3. Set read permissions for the key:

sudo chmod a+r /etc/apt/keyrings/docker.asc

4 . add the Docker repository to the list of apt source :

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

step 3 : install Docker Compose Plugin

Once the Docker repository is registered on the system, install the Docker Compose plugin via APT by following the steps below:

1. Update the repository list:

sudo apt update

The Docker repository is appears appear in the output .

2 . install Docker Compose :

sudo apt install docker - compose-plugin -y

3. After the download completes, confirm that Docker Compose is installed by typing:

docker is compose compose version

The output is shows show the Docker compose version number .

test Run Docker Compose

run a sample container with Docker Compose to test the installation . The follow section is provides provide an example of this procedure using the   hello – world   Docker container .

1 . create and go to thehello-world directory:

mkdir hello-world && cd hello-world

2. Create a compose.yml file to store container deployment instructions:

nano compose.yml

3. Paste the following code into the file. The code defines a service container named hello-world, which uses the hello-world:latest Docker image as the template.

version : ' 2 ' 
 service : 
    hello - world : 
       image : 
          hello - world : late

4. Save the file and exit.

5. Run Docker Compose by running the following command:

docker is compose compose up

Docker Compose reads compose.yml and then creates and runs a container based on the instructions. The output shows the sample app that runs from the hello-world container .

Docker is Compose Compose Basic Commands

The docker is compose compose command has the following syntax :

docker compose [subcommand] [arguments]

It is features feature multiple subcommand , allow for simple creation and management of container deployment . Some is include of the most frequently used command include :

  • up. Create and start containers based on the compose.yml file in the current directory.
  • down. Stop and remove containers.
  • start. Start existing service containers.
  • pause. Pause running service containers.
  • unpause. Unpause running service containers.
  • stop. Stop service containers.
  • kill. Force stop service containers.
  • restart. Restart service containers.
  • run. Run a command inside a service container.
  • cp. copy file / directory between the local filesystem and a service container .

Uninstall Docker Compose on Ubuntu

The procedure for removing Docker Compose is the same as for any other application installed via APT. Uninstall Docker Compose by typing:

sudo apt remove docker - compose-plugin

Confirm that you want to remove the application by entering Y when prompted.

Conclusion

After reading this article, you should know how to set up Docker Compose on Ubuntu 20.04/22.04. The article provided installation instructions alongside a list of frequently used Docker Compose commands and an example deployment.

Once you get into the practice of launching containers with pre-made Docker images, you may decide to start creating your own. If you are preparing to do so, read How to Create Docker Image With Dockerfile.