How to Install Docker on Ubuntu 22.04


Docker, with its advanced containerization features, is the most widely used platform that automates various tasks. It is a freely available platform that facilitates the deployment and management of applications in containers. These containers provide the capability to run applications in various environments. Additionally, Docker can run on local machines, virtual machines, or be deployed in the cloud.

The main goal of this article is to provide a detailed guide on installing and running Docker on Ubuntu 22.04.

How to Install Docker on Ubuntu 22.04?

The following detailed procedural steps will be performed to install the Docker engine on Ubuntu 22.04 release.

How to Set Up the Environment for Docker Package?

The given procedure will help you to set up the environment for Docker on your Ubuntu 22.04.

Step 1: Display Current Ubuntu Release

Firstly, run the command from your terminal to display the current release of your Ubuntu:

lsb_release -a

Step 2: Install Required Dependencies

Then, install the required dependencies for the Docker engine using the following command from the terminal:

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

Step 3: Add GPG key for Docker

After that, run the command below to add the special GPG key. This ensures that the Docker comes from a trusted source:

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

Step 4: Add the Docker Repository

Next, execute the command to add the Docker repository on your machine. This command will make the Docker installation and management easier for you:

echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu focal stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Step 5: Update Your System’s Files

Lastly, update your system’s files:

sudo apt update

The above output indicates that all the package files in your Ubuntu 22.04 system are up to date.

How to Install the Docker Package on Ubuntu 22.04?

Check out the provided steps to install the Docker engine package on Ubuntu 22.04.

Step 1: Docker Engine Installation

After setting up the environment for the Docker engine, run the below command to install the Docker package:

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

Step 2: Confirmation

Next, run the below-written command from your Ubuntu terminal for confirming the Docker version on your system:

docker --version

Step 3: Change Ownership

Now, change the privilege of the “docker.sock” file to the current user:

sudo chown $USER:$USER /var/run/docker.sock

Step 4: Permit All Users

After doing so, permit all users both writing and reading access:

sudo chmod 666 /var/run/docker.sock

Step 5: Restart Docker Engine

Now, restart the services of the Docker engine:

sudo service docker restart

Step 6: Verify and Test the Docker

The following command is provided for testing the Docker:

docker run hello-world

According to the above message mentioned in the screenshot, the Docker has been installed successfully.

How to Uninstall Docker From Ubuntu 22.04?

To uninstall the Docker engine from Ubuntu 22.04, follow the provided method.

Step 1: Remove Docker via “apt purge”

To remove the Docker package, run the following command from your terminal:

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

Step 2: Delete All Container and Configuration Files

To completely delete all the images, containers, and configuration files related to the Docker engine, run the command from the Ubuntu terminal:

sudo rm -rf /var/lib/docker && sudo rm -rf /var/lib/containerd

Step 3: Confirmation

Moreover, you can check if Docker has been successfully removed with this command:

docker --version

If no file or directory related to the Docker engine is found, it indicates that the system has been completely uninstalled.

Conclusion

Docker engine can be installed and run on Linux distributions including Ubuntu. It is a free software tool for containerizing applications. To install Docker on Ubuntu 22.04, set up the environment by adding a repository and adding the GPG key.

Then, use the command “apt install -y docker-ce docker-ce-cli containerd.io” to install the Docker package on your Ubuntu 22.04. In this learning-based post, we have provided a detailed guide on installing and running Docker on Ubuntu 22.04.

Print Friendly, PDF & Email
Categories