How to Install Docker Compose on Ubuntu 24.04

Install docker compose on ubuntu 24.04

Docker Compose is a powerful tool designed to streamline the development and deployment of applications constructed from multiple Docker containers. By providing a unified interface to manage these interconnected services, Docker Compose significantly reduces the complexity often associated with modern software systems. With its user-friendly YAML configuration format, Docker Compose empowers developers to effortlessly define and orchestrate intricate application environments. This facilitates rapid prototyping, testing, and deployment. This guide will walk you through the process to install Docker Compose on Ubuntu 24.04, enabling you to harness its benefits and efficiently manage your multi-container applications.

Installing Docker Compose on Ubuntu 24.04

Using Docker Compose on Ubuntu 24.04?

Let’s start with the guide.

Installing Docker Compose on Ubuntu 24.04

First of all, users need to check that Docker Engine and CLI are already installed on the Ubuntu system. Refer to the instructions for installing Docker on Ubuntu 24.04. Once installed, confirm the Docker version:

docker --version

docker --version

Let’s begin with the easiest one.

Method 1: Using the Ubuntu Default Repository

If you’re running Ubuntu 24.04 and need to set up Docker Compose from the standard system repositories, this guide will walk you through the process:

Step 1: Update Package List

Make sure users can see the newest software by updating the package database via the below command:

sudo apt update

Step 2: Install Docker Compose

The package database has been updated, allowing users to install Docker Compose on Ubuntu by specifying the ‘docker-compose‘ package name:

sudo apt install docker-compose

sudo apt install docker-compose

Important: If you encounter any problems, run the following command to install the Docker Compose plugin: sudo apt install docker-compose-plugin

Step 3: Verify Installation

Upon successful installation, users can validate Docker Compose installation by examining its version number:

docker compose version

docker compose version

The Docker Compose tool is successfully set up on your Ubuntu 24.04 machine.

Method 2: Using Docker Repository

Installing Docker Compose on Ubuntu 24.04 using the official Docker repository involves the following procedures:

Step 1: Install Docker Engine

Docker Compose relies on the Docker engine. If Docker isn’t installed, use apt to update your package index and install the Docker package:

sudo apt update
sudo apt install docker.io

After the installation is finished, launch Docker by starting and enabling the service:

sudo systemctl start docker
sudo systemctl enable docker

Step 2: Download Docker Compose

Once Docker is set up, individuals can acquire the latest Docker Compose build from GitHub. As an example, the stable release, version 2.26.1, is accessible through the wget” utility:

wget https://github.com/docker/compose/archive/refs/tags/v2.26.1.tar.gz

wget https://github.com/docker/compose/archive/refs/tags/v2.26.1.tar.gz

After that, unzip the file through the “tar” utility with the “xzf” option:

tar -xzf v2.26.1.tar.gz

tar -xzf v2.26.1.tar.gz

Step 3: Install Docker Compose

Open the extracted folder and use the ‘make’ command to set up Docker Compose:

cd compose-2.26.1
make install

make install

Important: If you encounter any problems, run sudo apt install docker-buildx-plugin to install Docker Engine or its dependencies.

Step 4: Create a Symbolic Link

To prevent conflicts after downloading, consider creating a symbolic link. The decision depends on user requirements:

sudo ln -s ~/compose-2.26.1/bin/build/docker-compose /usr/local/bin/docker-compose

Step 5: Verify Installation

Check Docker Compose is set up by typing ‘docker-compose’ into the terminal:

docker-compose

docker-compose

It confirms the installation of Docker Compose on Ubuntu.

Using Docker Compose on Ubuntu 24.04

Docker Compose is now ready for use. Begin configuring it by creating a .yml file with the following content:

Step 1: Create the “docker-compose.yml” File

First, create a docker-compose.yml file in the project directory. Next, define the services within this file:

nano docker-compose.yml

Now, users need to set the rules for docker-compose by adding the below lines in .yml configuration file:

version: '3'
services:
web:
image: nginx
ports:
- "80:80"
database:
image: postgres
environment:
POSTGRES_PASSWORD: mysecretpassword

nano docker-compose.yml

After that, save and close the file.

Validate the .yml File

Now, authenticate the file after setting permissions for docker-compose:

docker-compose config

docker-compose config

Step 2: Start Docker Compose Services

Initiate the services outlined in your YAML file by running docker-compose up -d:

docker-compose up -d

docker-compose up -d

Step 3: Check Containers Status

To view the current state of your containers, run the docker-compose ps command:

docker-compose ps

docker-compose ps

Step 4: Pull Down Containers

To terminate the container services, users can utilize the below command:

docker-compose down

docker-compose down

That is all from the guide.

Conclusion

To set up Docker Compose on Ubuntu 24.04, first ensure that Docker Engine and its command-line interface (CLI) are installed. Then, add Docker’s official repository and install Docker Compose using the apt package manager.

Once Docker Compose is installed, create a YAML configuration file named docker-compose.yml within your project directory. This file outlines the services that comprise your application. With the configuration in place, you can use Docker Compose to efficiently manage and run your application’s services.