Best Guide For Docker Compose Installation on Ubuntu 24.04

This guide intends to teach you Docker Compose Installation on Ubuntu 24.04. As you may know, Docker Compose is a tool that allows you to define and manage multi-container Docker applications using a simple YAML file.

The Docker Compose Installation on Ubuntu 24.04 simplifies configuration management. You can now proceed to the following steps to get a step-by-step guide provided by the Orcacore team to start your Docker Compose setup on your Ubuntu 24.04.

Simplifying Development with Docker Compose Installation on Ubuntu 24.04

Before you start your Docker Compose Installation on Ubuntu 24.04, you need to set up Docker on your server first. For this purpose, you must check this guide on Setting up Docker CE For Ubuntu 24.04.

Once you are done with installing Docker, you can proceed to the following steps to start your Docker Compose Installation on Ubuntu 24.04.

Step 1 – Download and Build Docker Compose on Ubuntu 24.04

First of all, you must visit the GitHub Reales Page for Docker Compose and use the following commands to download the latest Docker Compose version on Ubuntu 24.04.

At the current time, the latest version of Docker Compose is v.2.29.7. Use the following curl command to download it:

# mkdir -p ~/.docker/cli-plugins/

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

Then, you must set the correct permission for the Docker compose path on Ubuntu 24.04 with the following command:

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

Now your Docker Compose Installation on Ubuntu 24.04 must be completed. To verify it, you can check the Docker compose version:

docker compose version

In your output, you should see:

Output
Docker Compose version v2.29.7

Note: As we said at the beginning of the article, Docker Compose uses a YAML file to define and manage docker containers. In the next step, we want to show you an example of creating and using Docker Compose YAML File on Ubuntu 24.04.

Step 2 – Docker Compose yml File Example on Ubuntu 24.04

At this step, you have learned to complete the Docker Compose Installation on Ubuntu 24.04. Now you can learn how to create a docker-compose.yml file on Ubuntu 24.04.

To show an example, we will create a web server environment using the official Nginx image from DockerHub.

First, you need to create a new directory in your home folder, then navigate into it with the following commands:

# mkdir ~/compose-demo
# cd ~/compose-demo

Then, you must create a folder to serve as the document root for the Nginx environment with the following command:

mkdir app

Now you must create a new index.html file in the document root with your favorite text editor like Vi Editor or Nano Editor:

vi app/index.html

Paste the following content into your file:

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Docker Compose Demo</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/kognise/water.css@latest/dist/dark.min.css">
</head>
<body>

    <h1>This is a Docker Compose Demo Page.</h1>
    <p>This content is being served by an Nginx container.</p>

</body>
</html>

Once you are done, save and close the file.

Next, you can create your Docker Compose YML File:

vi docker-compose.yml

Then, paste the following content into the file:

version: '3.8'
services:
  web:
    image: nginx:alpine
    ports:
      - "8000:80"
    volumes:
      - ./app:/usr/share/nginx/html

Once you are done, save and close the file.

Note: The version specified at the top defines the syntax and features available for that configuration. For example, version: ‘3.8’ indicates that the file is using version 3.8 of the Compose file format, which includes features like networks, volumes, and services.

Now that you have learned Docker Compose Installation Ubuntu 24.04 and Creating Example YAML File, you can now use Docker Compose to run the container.

Step 3 – Run Container with Docker Compose on Ubuntu 24.04

At this point, you can easily run the environment you have created in the above step. To do this, you can easily use the following Docker Compose command:

docker compose up -d

In your output, you should see:

Docker Compose Installation on Ubuntu 24.04 - Run Containers

As you saw, the container is now up and running.

To see that your container is active, run the following command:

docker compose ps

In your output, you should see:

Check Container Status with Docker Compose

Now you can access the Docker Compose demo page on Ubuntu 24.04 by typing your server’s IP address in your web browser followed by “:8000”:

http://your-IP-address:8000
Test Docker Compose Ubuntu 24.04

Step 4 – Essential Docker Compose Commands

  • Check Logs:
docker compose logs
  • Pause Container:
docker compose pause
  • Unpause Container:
docker compose unpause
  • Stop Container:
docker compose stop
  • Remove Container and Base Image:
# docker compose down 
# docker image rm nginx:alpine

Step 5 – Uninstall Docker Compose From Ubuntu 24.04

At this step, you have seen that you can easily finish the Docker Compose Installation on Ubuntu 24.04, Create a YAML File, and Use Docker Compose.

Now if you plan to remove and uninstall Docker Compose, you can run the command below:

rm $DOCKER_CONFIG/cli-plugins/docker-compose

Or, if you have installed Docker Compose for all users, run the following command:

rm /usr/local/lib/docker/cli-plugins/docker-compose

Note: To check where Compose is installed, you can run the command below:

docker info --format '{{range .ClientInfo.Plugins}}{{if eq .Name "compose"}}{{.Path}}{{end}}{{end}}'

That’s it, you are done with Docker Compose Installation on Ubuntu 24.04. For more information, you can check the Official Docker Docs.

Conclusion

As you saw, the Docker Compose Installation on Ubuntu 24.04 is straightforward. You just need to install Docker CE and download and build the latest version of Compose. Then, you can easily use docker-compose to manage your containers.

Hope you enjoy it. Also, you may like to read the following articles:

Run Nextcloud on Ubuntu 24.04

LAMP Stack Installation on Ubuntu 24.04

Enable NTP Service on Ubuntu 24.04

Install WineHQ on Ubuntu 24.04

FAQs

How do I create a Docker Compose file?

Create a docker-compose.yml file in your project directory and define your services, networks, and volumes in YAML format. The example of creating a docker-compose YAML file is explained in the above guide on Docker Compose installation on Ubuntu 24.04.

How do I start my application with Docker Compose?

You can use the docker compose up command.

Can I run Docker Compose in detached mode?

Yes, use the -d flag to run it in detached mode: docker compose up -d

Newsletter Updates

Enter your email address below and subscribe to our newsletter

Stay informed and not overwhelmed, subscribe now!