How to install docker compose on ubuntu 22. 04

How to Install Docker Compose on Ubuntu 22.04

Docker is a software platform utilized for the development of Containers-based (lightweight execution environments) applications that have the capability of sharing the operating system kernel in isolation. Whereas 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.

This write-up will demonstrate the method of installing Docker Compose on Ubuntu 22.04. So, let’s start!

Note: Before moving towards the installation of Docker Compose, you should install Docker on your Ubuntu

Sponsored
22.04 system; If you do not have it already.

How to install Docker on Ubuntu 22.04

You must follow the below-given procedure for installing Docker on Ubuntu 22.04.

Step 1: Update system repositories

First of all, open up the terminal by hitting “CTRL+ALT+T” in Ubuntu 22.04 and write out the below-given commands for updating the system repositories:

$ sudo apt update

How to install docker compose on ubuntu 22. 04 1

Upgrade the system packages as well:

$ sudo apt upgrade

How to install docker compose on ubuntu 22. 04 2

Step 2: Install required dependencies

After updating the system packages, the next step is to install required dependencies for Docker:

$ sudo apt install lsb-release ca-certificates apt-transport-https software-properties-common -y

How to install docker compose on ubuntu 22. 04 3

How to install docker compose on ubuntu 22. 04 4

Step 3: Adding Docker repository to system sources

When a Docker repository is added to the system sources, it makes the Docker installation easier and provides faster updates.

To add the Docker repository to the system sources, firstly, import the Docker GPG key required for connecting to the Docker repository:

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

How to install docker compose on ubuntu 22. 04 5

After doing so, execute the following command for adding the Docker repository to your Ubuntu 22.04 system sources list:

See also  How to Find a Package that Provides a File on Ubuntu
$ 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 > /dev/null

How to install docker compose on ubuntu 22. 04 6

Step 4: Update system packages

After adding Docker repository to the system sources, again update the system packages:

$ sudo apt update

How to install docker compose on ubuntu 22. 04 7

Step 5: Install Docker on Ubuntu 22.04

At this point, our Ubuntu 22.04 system is all ready for the Docker installation:

$ sudo apt install docker-ce

Note that we are utilizing the “docker-ce” package instead of “docker-ie” as it is supported by the official Docker repository:

How to install docker compose on ubuntu 22. 04 8

Enter “y” to permit the Docker installation to continue:

How to install docker compose on ubuntu 22. 04 9

The below-given error-free output indicates that Docker is successfully installed on our Ubuntu 22.04 system:

How to install docker compose on ubuntu 22. 04 10

Step 6: Verify Docker status

Now, execute the below-given “systemctl” command to verify if the Docker is currently active or not on your system:

$ sudo systemctl status docker

How to install docker compose on ubuntu 22. 04 11

Now, let’s check out the method of installing Docker Compose on Ubuntu 22.04.

How to install Docker Compose on Ubuntu 22.04

You must follow the below-given procedure for installing Docker Compose on Ubuntu 22.04.

Step 1: Download Docker Compose package

First of all, verify the latest version of the Docker Compose package from the release page. For example, at this moment, the most stable version of Docker Compose is “2.5.0”.

So, we will create a directory with the help of the following “mkdir” command:

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

How to install docker compose on ubuntu 22. 04 12

After doing so, utilize the below-given “curl” command for installing Docker Compose on Ubuntu 22.04:

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

How to install docker compose on ubuntu 22. 04 13

Step 2: Docker Compose Installation

In the next step, set the executable permissions to the “docker-compose” command:

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

How to install docker compose on ubuntu 22. 04 14

Then, verify the version of the installed Docker Compose:

$ docker compose version

As you can see, on our Ubuntu 22.04 system, we have installed Docker Compose version “2.5.0”:

How to install docker compose on ubuntu 22. 04 15

Step 3: Create a docker-compose.yml file

Before setting up a “docker-compose.yml” file, write out the below-given “mkdir” command for creating a new directory in “home”:

$ mkdir ~/compose-demo

How to install docker compose on ubuntu 22. 04 16

Then, switch to the newly created directory:

$ cd ~/compose-demo

How to install docker compose on ubuntu 22. 04 17

Now, we will create a new application folder named “app” that will serve as a document root for our Nginx environment:

$ mkdir app

How to install docker compose on ubuntu 22. 04 18

Next, open the “nano” editor and create an “index.html” file:

$ nano app/index.html

How to install docker compose on ubuntu 22. 04 19

In the opened file, write out the following code and press “CTRL+O” to save it:

lang=“en”>

charset=“utf-8”>

Docker Compose Demo</title>

rel=“stylesheet”   href=“https://cdn.jsdelivr.net/gh/kognise/water.css@latest/dist/>

</head>

This is a Docker Compose Demo Page.</h1>

This content is being served by linuxhint.com</p>

</body>

</html>

How to install docker compose on ubuntu 22. 04 20

At this point, we are all ready to set up the “docker-compose.yml” file. To do so, create “docker-compose.yml” file:

$ nano docker-compose.yml

How to install docker compose on ubuntu 22. 04 21

Then, add the below-given code in it:

version: ‘3.7’

services
:

web
:

image
: nginx:alpine

ports
:

“8000:80”

volumes
:

– ./app:/usr/share/nginx/html

How to install docker compose on ubuntu 22. 04 22

Now, move to the next step.

Step 4: Run Docker Compose

As soon as your environment is up, you can run the below-given “docker-compose” command. This command will create a container for web service, download the essential Docker images, and execute the containerized environment in the background:

$ docker-compose up -d

How to install docker compose on ubuntu 22. 04 23

You can also validate that the container is active or not with the help of the following command:

$ sudo docker-compose ps

How to install docker compose on ubuntu 22. 04 24

The above-given output indicates that we can now access our demo application by browsing the “localhost:8000” web page:

http://localhost:8000/

If you have carefully followed the previously given steps, then you will see the following web page:

How to install docker compose on ubuntu 22. 04 25

We have compiled the simplest method to install Docker Compose on Ubuntu 22.04.

Conclusion

For the installation of Docker Compose, firstly, you have to utilize the “$ sudo apt install docker-ce” command to install Docker on your system. Then, download the latest version of the Docker Compose package from the release page and install it. After doing so, create a “docker-compose.yml” file and execute the “$ docker-compose up -d” command. This write-up demonstrated the method of installing Docker Compose on Ubuntu 22.04.


Discover more from Ubuntu-Server.com

Subscribe to get the latest posts sent to your email.

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply