Before installing Docker, you need to have installed an Ubuntu Sever. For this guide we have used: Ubuntu Server 22.04.3 LTS


Docker Installation


Before you install Docker Engine for the first time on a new host machine, you have to set up the Docker repository. Afterward, you can install and update Docker from the repository. 


  1. Set up Docker’s apt repository


Commands

Description

sudo apt-get update

This command updates the list of available packages and their versions in the apt repositories. 

sudo apt-get install ca-certificates curl

Installs the ca-certificates and curl packages. ca-certificates is necessary for handling security certificates, and curl is a tool for transferring data to or from a server.

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

This command creates a directory /etc/apt/keyrings if it doesn't exist, with permissions 0755 which grant read and execute permissions to all users and write permission only to the owner.

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

This command creates a directory /etc/apt/keyrings if it doesn't exist, with permissions 0755 which grant read and execute permissions to all users and write permission only to the owner.

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

Changes the permissions of the docker.asc file to be readable by all users (a+r).

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 adds an entry to the docker.list file in the directory /etc/apt/sources.list.d/. The entry includes the Docker repository for Ubuntu with the correct architecture and the codename of the Ubuntu OS version.

sudo apt-get update

This command updates the list of available packages and their versions in the apt repositories again after adding the Docker repository


  1. Install the Docker packages:


Commands

Description

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

This command is used to install related tools necessary for building, running, and managing Docker containers and applications on your system


  1. Verify that the Docker Engine installation is successful by running the hello-world image:


Commands

Description

sudo docker run hello-world

Docker will pull the "hello-world" image from the Docker Hub repository (if it's not already available locally), create a new container based on that image, start the container, and then display the message from the "hello-world" image indicating that your Docker installation is working


As a result of executing these commands you must obtain the following result: