Greenwebpage Community Blog Tutorials How to Install Docker Compose on Ubuntu 22.04
Tutorials

How to Install Docker Compose on Ubuntu 22.04

How to Install Docker Compose on Ubuntu 22

Docker is a platform commonly used for developing, testing, and deploying applications inside containers. Docker Compose facilitates the management and running of several containers together with a simple configuration file. 

In short, Docker Compose can easily manage complex applications, making the process from building to deployment more efficient.

In this educational write-up, you will explore the procedure for installing the Docker Compose on Ubuntu 22.04.

How to Install Docker Compose on Ubuntu 22.04?

The following procedure will be used for installing the Docker Compose on your Ubuntu 22.04.

Step 1: Install Essential Packages 

To install the Docker package, first install the required packages on your machine:

sudo apt install ca-certificates curl

You can inspect the package files like Curl, during the installation process.

Step 2: Create the Keyrings directory for Docker

Next, run the following command to create a directory with specific permissions (i.e. 0755):

sudo install -m 0755 -d /etc/apt/keyrings

This command has created a keyrings directory at the local path

Step 3: Download the Docker GPG Key via Curl

You can now download the Docker GPG key from the specified URL and save it to the keyrings directory in your local folder:

sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc

With the help of this command, the docker.asc file is now available on your Ubuntu system.

Step 4: Set Permission for the Docker GPG key

Utilize the provided command below to allow users to read the files located in the keyrings directory:

sudo chmod a+r /etc/apt/keyrings/docker.asc

The chmod a+r allowed all users to read the Docker GPG files from the specified path (/etc/apt/keyrings/docker.asc).  

Step 5: Add Docker Repository

By executing the command, you can easily add the Docker repository to Ubuntu’s package list on your Ubuntu system:

echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

This command aims to enable secure access to Docker packages for installation and updates.

Step 6: Refresh Package List

To refresh and update your Ubuntu package repository, run the command from the terminal:

sudo apt update

Make sure, the Docker files have been added to the package list. 

Step 7: Install Docker and Its Dependencies

Once you have completed the process mentioned above, your system is now ready to install Docker and its dependencies through this command:

sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin -y

You can observe from the above output that all the associated files and dependencies have been configured for the Docker Compose on your Ubuntu system. 

Step 8: Test Docker Installation

Run the following “hello-world” command to test the installation of the Docker on your system: 

sudo docker run hello-world

The message “Hello from Docker!” Indicates that the Docker Compose is correctly installed on your Ubuntu 22.04 system. 

Step 9: Verify Docker Compose Version

Upon completing the installation and testing process, you can check the current version of Docker Compose via the command:

docker compose version

Here, you can see the installed version of Docker Compose on your Ubuntu 22.04 is v2.24.5.

Through these simple commands, you have successfully installed the Docker Compose on your Ubuntu 22.04 machine. 

How to Uninstall Docker Compose from Ubuntu 22.04

Perform the provided steps for uninstallation of the Docker Compose from your Ubuntu 22.04 system.

Step 1: Uninstall Docker Components

You can execute the purge option with the apt command to remove the complete package from your Ubuntu system. To remove the Docker Compose and its components from your system, simply run the command from the terminal window:

sudo apt purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-ce-rootless-extras -y

This command is executed to completely remove the docker package from the Ubuntu system.

Step 2: Remove Docker Directory

After the uninstallation process, it is also important to remove the Docker directory, which contains data such as images and volumes:

sudo rm -rf /var/lib/docker

Step 3: Remove Container Directory

To remove the container directory located at /var/lib/containerd run the command:

sudo rm -rf /var/lib/containerd

Step 4: Verify Docker Uninstallation 

To ensure Docker has been completely uninstalled from your Ubuntu 22.04 system, execute the given below command:

docker compose version

If Docker has been properly uninstalled, the command will return a message stating that no such file or directory exists on your terminal screen.

Conclusion

It is easy to install the Docker Compose on your Ubuntu 22.04 through a few commands. After setting up an environment, utilize the apt installer to configure the Docker and its components on your system. This write-up provided a step-by-step procedure for installing the Docker Compose on a Linux-based system, including Ubuntu 22.04.

You may also like reading How to install Typo3 on Ubuntu 24.04.

Exit mobile version