UbuntuUbuntu Based

How To Install Docker Compose on Ubuntu 24.04 LTS

Install Docker Compose on Ubuntu 24.04

In this tutorial, we will show you how to install Docker Compose on Ubuntu 24.04 LTS. Docker Compose is a tool that extends Docker’s capabilities by allowing you to define and run multi-container Docker applications. With Docker Compose, you can use a YAML file to configure your application’s services, networks, and volumes. This declarative approach simplifies the process of managing complex applications that consist of multiple interconnected containers.

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 24.04 (Noble Numbat). 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 and any other Debian-based distribution like Linux Mint.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • Basic familiarity with the command line interface.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies.
  • An Ubuntu 24.04 system with root access or a user with sudo privileges.

Install Docker Compose on Ubuntu 24.04

Step 1. Updating the Package Repository.

Before installing Docker Engine and Docker Compose, it’s crucial to ensure that your Ubuntu system is up to date. Open a terminal and run the following commands to update the package lists and install any available updates:

sudo apt update
sudo apt upgrade

Once the update process is complete, you can proceed with installing the necessary dependencies for Docker.

Step 2. Installing Docker Engine.

To install Docker Compose, you first need to have Docker Engine installed on your Ubuntu system. Follow these steps to install Docker Engine:

Add Docker’s official 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

Set up the Docker repository:

echo "deb [arch=amd64 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 > /dev/null

Update the package lists and install Docker Engine:

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

Verify the Docker installation by running the following command:

sudo docker run hello-world

If the installation was successful, you should see a message confirming that Docker is working correctly.

Step 3. Installing Docker Compose.

With Docker Engine installed, you can now proceed to install Docker Compose. There are two primary methods to install Docker Compose on Ubuntu 24.04 LTS:

  • Method 1: Using apt Package Manager

Install Docker Compose:

sudo apt update
sudo apt install docker-compose

Verify the installation by checking the version:

docker-compose --version
  • Method 2: Manual Installation from GitHub

Download the current stable release of Docker Compose:

sudo curl -L "https://github.com/docker/compose/releases/download/2.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

Apply executable permissions to the binary:

sudo chmod +x /usr/local/bin/docker-compose

Verify the installation by checking the version:

docker-compose --version

Step 4. Configuring Docker Compose.

To ensure smooth usage of Docker Compose, it’s recommended to set up the necessary user permissions. By default, running Docker commands requires root privileges. However, you can create a Docker group and add your user to it to avoid using sudo for every Docker command.

Create the Docker group:

sudo groupadd docker

Add your user to the Docker group:

sudo usermod -aG docker $USER

Log out and log back in for the changes to take effect, or run the following command to activate the group membership:

newgrp docker

Now you can run Docker and Docker Compose commands without using sudo.

Step 5. Creating Your First Docker Compose File.

Docker Compose uses a YAML file to define the services, networks, and volumes for your application. Let’s create a simple docker-compose.yml file to understand its structure.

Create a new directory for your project:

mkdir my-project
cd my-project

Create a file named docker-compose.yml and open it in a text editor:

nano docker-compose.yml

Add the following content to the file:

version: '3'
services:
  web:
    image: nginx
    ports:
      - "80:80"
  db:
    image: mysql
    environment:
      MYSQL_ROOT_PASSWORD: secret

In this example, we define two services: web and db. The web service uses the nginx image and maps port 80 of the container to port 80 of the host. The db service uses the MySQL image and sets the root password using an environment variable.

Step 6. Running Your First Docker Compose Project.

With the docker-compose.yml file created, you can now start your application using Docker Compose.

In the same directory as your docker-compose.yml file, run the following command to start the services:

docker-compose up -d

To view the running containers, use the following command:

docker-compose ps

To stop the services, run:

docker-compose down

Docker Compose makes it easy to manage the lifecycle of your application’s services, from starting and stopping containers to viewing logs and scaling services.

Congratulations! You have successfully installed Docker Compose. Thanks for using this tutorial for installing the Docker Compose on the Ubuntu 24.04 LTS 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