How To Install Docker on Ubuntu

By Chandrashekhar Fakirpure

Updated on Feb 02, 2024

In this article, we will show how to install Docker on Ubuntu 22.04.

Docker is a remarkably popular containerization tool, which is fairly easy to use. It makes it easy to duplicate applications across multiple servers and to build different server environments for a single server application.

Docker is a software tool which enables you to create and deploy standalone containers which contain a specific element of a software project. For example, you may deploy an apache container, a MySQL container, and a PureFTP container in order to create a simple web server. Each Docker container receives its own CPU, memory, block I/O, and network resources in order to segment the server between applications.

We have covered installation of Docker on Ubuntu 22.04 using the apt repository.

Prerequisites

  • A Ubuntu 22.04 installed dedicated server or KVM VPS.
  • A root user access or normal user with sudo privileges.

Step 1 - Update The Server

Keep the server up to date. Use following command to update the Ubuntu server.

apt update

Step 2 - Install Dependencies

Install the required dependencies for Docker:

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

Step 3 - Docker’s Official GPG Key and Repository

mkdir -m 0755 -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

Add the Docker Repository

echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Step 4 - Install Docker Engine

First, update the apt package using following command:

apt-get update

The following command will download and install Docker Engine, containerd, andDocker:

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

Verify the installation.

docker run hello-world

The following screen will appear upon a successful installation of Docker::

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:63421b18c1443a9a85139225293fae7541fb40b7832d9deff80b6a9a75ce3604
Status: Downloaded newer image for hello-world:latest

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/

That’s it. The docker is installed now. You can deploy Docker containers.

We have seen, how to install Docker on Ubuntu 22.04. Here is the Docker's official Documentation.