UbuntuUbuntu Based

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 powerful tool that allows you to define and manage multi-container Docker applications using a single configuration file. It simplifies the process of setting up and running complex applications that consist of multiple containers, each with its own dependencies and configurations.

With Docker Compose, you can define the services that make up your application, their dependencies, network configurations, volumes, and other settings in a single YAML file. This file serves as a blueprint for your application, making it easy to spin up or tear down the entire application stack with a single command.

One of the key benefits of using Docker Compose is its ability to streamline the development and deployment processes. By defining your application’s components and their relationships in a single file, you can ensure consistent and reproducible environments across different stages of the development lifecycle, from local development to production deployment.

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 user or 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. Before installing any new software, it’s always a good practice to update the package database on your Ubuntu system. Open a terminal and run the following command:

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.27.0/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

To ensure that Docker Compose has been installed correctly, you can check its version by running the following command:

docker compose version

Output:

Docker Compose version v2.27.0

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!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button