How to Install Docker and Docker Compose on Ubuntu 22.04?

In this post we are discussing the importance of docker and see why learning docker is must for IT professionals?

How to Install Docker and Docker Compose on Ubuntu 22.04?

Installing Docker and Docker Compose - How to Install Docker and Docker Compose on Ubuntu 22.04?

Welcome to another tutorial on Docker, today we will learn to install docker and docker compose on Ubuntu 22.04. Step by step tutorial for installing Docker and Docker Compose on Ubuntu 22.04. We have also provided step by step video instruction for installing Docker and Docker compose on the Ubuntu 22.04 Operating System. If you are using Ubuntu 24.04 then steps given in this tutorial will also apply for the same. So, let's get started with the installation steps.

Why Docker and Docker compose?

Docker is a set of tools and services for running the containerized applications on the top of the underlying operating system. Docker service uses the services of the host machine to run the containerized applications in a much secure and isolated environment. Docker runs the containerized applications know as docker images on the host operating system. Docker images as fast as it uses the host operating services and there is no need to spin up whole new operating system.

Docker Compose is another tool which uses docker services to run the docker images in a much easier way. In this tutorial we are going to install docker and docker compose on the Ubuntu host operating system.

How to Install Docker and Docker compose on Ubuntu 22.04? Step-by-step tutorial.

We have recorded step by step instruction to install Docker and Docker compose on Ubuntu 22.04. Here is the video tutorial for install Docker and Docker compose.

Step 1: First of all update your Ubuntu 22.04 operating system

Here is the command to update you Ubuntu 22.04 operating system:

sudo apt update

Step 2: Install prerequisite packages

Next we have to install prerequisite packages which is required on the system. Here is the command for installing the pre-requisites packages:

sudo apt install apt-transport-https ca-certificates curl software-properties-common

Step 3: Add the GPG key of the official Docker repository on the Ubuntu 22.04 operating system

Next we should add the GPG key of the official Docker repository to your Ubuntu 22.04 operating system. This will enable us to use official Docker repository. Here is the command that you should run on the terminal:

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

Step 4: Adding Docker repository APT sources

The next step is to add the Docker repository to APT sources. Use following command to do so:

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

Step 5: Update Ubuntu 22.04

Run the following command to update your Ubuntu 22.04 OS:

sudo apt update

Step 6: Use official Docker repo

You should run the following command to to install from the Docker repo instead of the default Ubuntu repo:

apt-cache policy docker-ce

Step 7: Install docker

Finally we have prepared our system for the installation of docker. Run following command to install docker on Ubuntu 22.04 operating system:

sudo apt install docker-ce

Step 8: Check the status of docker service

We have completed the installation of docker on Ubuntu 22.04 machine and now its time to check the status of docker service. Run the following command to see the status of docker service:

sudo systemctl status docker

Above command should display following if docker service is running:

docker.service - Docker Application Container Engine

     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset>

     Active: active (running) since Sat 2024-10-12 18:22:11 IST; 17min ago

TriggeredBy: ● docker.socket

       Docs: https://docs.docker.com

   Main PID: 897 (dockerd)

      Tasks: 10

     Memory: 103.9M

        CPU: 3.063s

     CGroup: /system.slice/docker.service

             └─897 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/conta>



Oct 12 18:22:10 user-VirtualBox dockerd[897]: time="2024-10-12T18:22:10.3045207>

Oct 12 18:22:10 user-VirtualBox dockerd[897]: time="2024-10-12T18:22:10.3720206>

Oct 12 18:22:11 user-VirtualBox dockerd[897]: time="2024-10-12T18:22:11.3951463>

Here is the screenshot of the output of above command which shows that the docker service is running:

Running Docker Service

Step 9: Run hello world docker

We have successfully installed docker and the docker service is running on our system. Next we will show you how to run first hello world docker on your system. Execute following command on the terminal to run hello world docker:

sudo docker run hello-world

Above command will download hello-world docker image from public docker repository and run on your system. Here is the output of hello world docker:

ser@user-VirtualBox:~/Desktop$ sudo docker run hello-world

[sudo] password for user: 


Hello from Docker!

This message shows that your installation appears to be working correctly.


To generate this message, Docker took the following steps:

 1. The Docker client contacted the Docker daemon.

 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.

    (amd64)

 3. The Docker daemon created a new container from that image which runs the

    executable that produces the output you are currently reading.

 4. The Docker daemon streamed that output to the Docker client, which sent it

    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:

 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:

 https://hub.docker.com/

For more examples and ideas, visit:

 https://docs.docker.com/get-started/

user@user-VirtualBox:~/Desktop$ 

Screen shot of the output of sudo docker run hello-world command:

hello world docker example

Step 10: Installing docker compose

You can install docker compose with following command:

sudo apt install docker-compose

You also install it with the following command sequences"

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

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

To check the version of docker compose you can run following command:

docker-compose version

In this tutorial we have learned the steps to install docker and docker-compose on Ubuntu 22.04 operating system. You can follow the same steps to install docker and docker-compose in Ubuntu 24.04.

Here are related tutorials: