How to install Docker and Docker Compose on Ubuntu 22.04

How to install Docker and Docker Compose on Ubuntu 22.04

Docker is an open-source platform that offers the development, distribution, and execution of applications. Docker uses OS-level virtualization to deliver applications in packages called containers. The container is a set of codes and their dependencies so that the application can run quickly without depending on the computing environment. Docker supports many operating systems such as Ubuntu, CentOS, etc.

Applications which are running in the Docker container can easily move from one system to another without any issue. Docker hub is a platform that offers a range of pre-developed docker images. Users can easily fetch these images and deploy them in their applications.

Features of Docker

  • Easier and faster configuration
  • An isolated, rapid framework
  • Increase productivity
  • Easily Scalable
  • Reduced Infrastructure and Maintenance Costs

Docker Compose is one of the famous tools of Docker, which is used to define and run multi-container Docker applications. In Docker compose, we use the YAML file to define and configure Docker containers for the application. After creating the YAML file, you can easily deploy and manage the application with a single command.

Features of Docker Compose

  • Multiple isolated environments on a single host
  • Preserve volume data when containers are created
  • Only recreate containers that have changed
  • Variables and moving a composition between environments

Also Read: How to Deploy the Kubernetes Dashboard on an Amazon EKS

Prerequisites

  • Server with Ubuntu 22.04 operating system
  • Access of Root user or another user with Sudo privileges

Enable Docker Repository

Install some pre-required packages with the following command.

sudo apt install screen vim wget curl -y

First, update the existing list of packages and the repositories.

sudo apt update -y

Install some pre-required apt packages to allow apt to use a repository over HTTPS.

sudo apt-get install ca-certificates curl gnupg lsb-release -y

Use the curl command to import the GPG key.

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

Run the following command to add the stable Docker repository on the Ubuntu server or the system.

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

Install the Docker package

After enabling the Docker repository, we need to update the repositories.

sudo apt update -y

Now, we can easily install the latest docker package with the following command.

sudo apt-get install docker-ce containerd.io docker-ce-cli -y

Now start the service of Docker with the following command.

sudo systemctl start docker

To check the status of the Docker service, use the below command.

sudo systemctl status docker

To check the Docker version, run the following command.

docker --version
Checking Docker version

Install a specific Docker version

If you want to install a particular Docker version from the Docker repository, then first check the available version of Docker in the Docker repository.

sudo apt-cache madison docker-ce
Available Docker versions

For example, if you want to install the Docker version 5:20.10.13~3-0~ubuntu-jammy then run the following command.

sudo apt-get install docker-ce=5:20.10.13~3-0~ubuntu-jammy docker-ce-cli=5:20.10.13~3-0~ubuntu-jammy containerd.io -y

To check the Docker is properly installed and working, simple run the hello-world image with the following command.

sudo docker run hello-world

After executing the above command, you will get an output like this.

Using hello-world Docker image

Manage the Docker service

We can easily manage the docker service with the following commands. These commands will work in the same way on all Linux-based systems and servers.

  • To Enable the Docker service, run the following command.
sudo systemctl enable docker
  • To start the Docker service, run the following command.
sudo systemctl start docker
  • To check the status of the Docker service, run the following command.
sudo systemctl status docker
  • To stop the Docker service, run the following command.
sudo systemctl stop docker
  • To disable the Docker service, run the following command.
sudo systemctl disable docker

Install the Docker Compose

Docker Compose is an open-source tool for developing and sharing multi-container applications. Compose allows us to define services in YAML files and initiate or shut down everything with a single command.

After enabling the Docker repository, run the following command to install the Docker compose.

sudo apt-get install docker-compose-plugin -y

Run the following command to check the Docker Compose version.

sudo docker compose version
Checking Docker Compose version

We have successfully configured the Docker Compose on Ubuntu 22.04.

Conclusion

In today’s tutorial, we have learned about Docker and Docker Compose and how we can install them on Ubuntu 22.04. You guys can follow the same tutorial to install the Docker and Docker Compose on Ubuntu 18.04 and Ubuntu 20.04.

If you guys have any queries or issues, let me know in the comments sections.