Guide to Installing Docker on Ubuntu 22.04 LTS

Guide to Installing Docker on Ubuntu 22.04 LTS

Introduction to Docker and Ubuntu 22.04 LTS

Brief Overview of Docker

In this guide, “Installing Docker on Ubuntu 22.04” will be our focus, as we take you through the steps to successfully set it up on your system.

Docker is a software platform that facilitates the creation, testing, and deployment of applications quickly and efficiently.

Docker “containerizes” applications into self-contained units called containers, providing everything needed to run the software. Thanks to Docker, your applications can operate smoothly and consistently in any environment.

Containers operate in isolation from the host system and other containers, somewhat like in a virtual sandbox.

Prerequisites for Installing Docker on Ubuntu 22.04 LTS

Prerequisites: Before proceeding with the installation of Docker, it is necessary to have a system with Ubuntu 22.04 LTS already installed. This system can be a virtual machine, a VPS server, or a dedicated server. Here are the preliminary steps to prepare for the installation.

Connecting as Root User: To connect to your system as the root user, use the following SSH command:

ssh root@ip_macchina 

and enter the password.

When prompted to enter the password, type it. It is normal that no characters are displayed on the screen while typing the password.

Connecting with a User other than Root: If you prefer to connect with a different username, for example, “jammy”, replace “root” with the desired username in the SSH command. Here is an example:

ssh jammy@ip_macchina

You will need to enter the password associated with the “jammy” user.

Necessary Updates Before Installing Docker

Before proceeding with the installation of Docker on Ubuntu 22.04 LTS, it is crucial to ensure that the system is updated with the latest versions of software packages. This step ensures that you are using the most recent and secure versions of the software.

To update the list of available packages, open the terminal and type the following command:

sudo apt update

After updating the list of packages, it is likely that there are updates available for the software already installed on your system. To install these updates, execute:

sudo apt upgrade

Respond with Y (Yes) or S (Sì) and press ENTER to proceed with the upgrade.

Installation of Docker Engine on Ubuntu 22.04 LTS

Installing the Docker Repository

To ensure that Docker functions correctly on Ubuntu 22.04 LTS, begin by installing some necessary packages.

To install the packages, use the following command:

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

Respond with Y (Yes) or S (Sì) and press ENTER to proceed with the update.

The next step is to add Docker’s GPG key. This is necessary for Ubuntu to verify the authenticity of the Docker packages you are about to install. Add the GPG key with the following command:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Finally, add the repositories to install Docker via APT:

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu jammy stable"

Press ENTER when prompted to confirm and proceed.

Actual Installation of Docker Engine

Now that you have prepared your Ubuntu 22.04 system with all the necessities, you are ready to install Docker.

To proceed with the installation, type the following command:

sudo apt install docker-ce

When prompted to confirm the installation, respond with Y (Yes) or S (Sì) and press ENTER.

Post-Installation Configuration of Docker on Ubuntu 22.04 LTS

Configuring Docker to Start on System Boot

After installation, Docker is not automatically set to start with the system.

To configure Docker to start automatically on system boot, type the following command:

sudo systemctl enable docker

This step is crucial, especially if you use Docker containers that need to be constantly operational or require an automatic restart.

Testing the Installation of Docker on Ubuntu 22.04

Verifying Docker Version and Status

After completing the Docker installation, it’s important to verify that everything is set up correctly. The first step is to check the installed version of Docker.

Type this command

docker -v

You should see information about the version on the terminal, like in this example

Docker version 24.0.7, build afdd53b

The next step is to verify the status of Docker to ensure it is active and functioning. Run the following command:

sudo systemctl status docker

You should see an output similar to this

* docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2023-11-16 11:28:10 UTC; 2h 13min ago
TriggeredBy: * docker.socket
       Docs: https://docs.docker.com
   Main PID: 15477 (dockerd)
      Tasks: 10
     Memory: 87.3M
        CPU: 1.046s
     CGroup: /system.slice/docker.service
             `-15477 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

If under the “Active” entry you see “active (running)”, it means that Docker is active and functioning. To exit the status view, press Q on your keyboard.

Running a Test Docker Container

Let’s move on to creating your first test Docker container.

As with all tests, we will use the renowned “Hello World!”

To get started with Docker, there’s nothing better than running the classic “Hello World!” test to confirm that Docker has been correctly installed and is functioning as expected on your Ubuntu 22.04.

Type this command in the terminal:

docker run hello-world

If you receive an output like this, you have successfully created your first Docker container.

Hello from Docker! This message shows that your installation appears to be working correctly.<br>...

Conclusions

In this tutorial, we have seen how installing Docker on Ubuntu 22.04 is a really easy and quick procedure. Now you will have access to all the capabilities of Docker.

If you are interested in delving deeper, check out our other guides dedicated to Linux.

Leave a Reply

Your email address will not be published. Required fields are marked *