How To Install Docker Compose on Ubuntu 22.04 LTS

Install Docker Compose on Ubuntu 22.04

In this tutorial, we will show you how to install Docker Compose on Ubuntu 22.04 LTS. For those of you who didn’t know, Docker Compose is a utility that permits you to run multi-container application setups based on YAML definitions. It creates fully customized environments with multiple containers that have the capability to share data volumes and networks using service definitions. Once you have a Compose file, you can create and start your application with a single command.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Docker Compose on Ubuntu 22.04 (Jammy Jellyfish). You can follow the same instructions for Ubuntu 22.04 and any other Debian-based distribution like Linux Mint, Elementary OS, Pop!_OS, and more as well.

Prerequisites

  • A server running one of the following operating systems: Ubuntu 22.04, 20.04, and any other Debian-based distribution like Linux Mint.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • A non-root sudo useror access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Docker Compose on Ubuntu 22.04 LTS Jammy Jellyfish

Step 1. First, make sure that all your system packages are up-to-date by running the following apt commands in the terminal.

sudo apt update
sudo apt upgrade
sudo apt install ca-certificates curl gnupg lsb-release

Step 2. Installing Docker.

By default, Docker is not available on Ubuntu 22.04 base repository. Now run the following command below to add the Docker repository to the system:

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list

Next, import the GPG key to your system:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

After the repository is enabled, now install the latest version of the Docker package using the below command:

sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin

You can verify that Docker is installed and about the current version:

docker -v

After successfully installed, enable Docker (to start automatically upon system boot), start, and verify the status using the commands below:

sudo systemctl enable docker
sudo systemctl start docker
sudo systemctl status docker

For additional resources on installing and managing Docker, read the post below:

Step 3. Install Docker Compose on Ubuntu 22.04.

Now run the following command below to download the stable version of Docker Compose from the GitHub page:

mkdir -p ~/.docker/cli-plugins/
curl -SL https://github.com/docker/compose/releases/download/v2.12.2/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-compose

Once the file is downloaded, make it executable by this command:

chmod +x ~/.docker/cli-plugins/docker-compose

Verify that Docker Compose is installed correctly by checking the version:

docker compose version

Output:

Docker Compose version v2.12.2

Step 4. Create a Sample Docker Compose File.

Let’s create a directory that holds our Compose file:

mkdir sample-test
cd sample-test

For testing purposes, I will create a sample test docker-compose YAML file using a nano text editor:

nano docker-compose.yaml

Add the following file:

version: '1.1'
services:
   hello-world:
      image:
         hello-world:latest 

Save and close the file, then use the Docker Compose command to execute the code given in the file, which simply says to pull the image hello-world and create a container with that:

sudo docker-composer up

Your environment is now up and running in the background. To verify that the container is active, you can run:

docker compose ps

Congratulations! You have successfully installed Docker Compose. Thanks for using this tutorial for installing the Docker Compose on Ubuntu 22.04 LTS Jammy Jellyfish system. For additional help or useful information, we recommend you check the official Docker website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!