Install Docker CE on Ubuntu 22.04

This short tutorial shows you how to install Docker CE on Ubuntu 22.04. Docker is an open-source project that allows you to run applications in isolated containers. Docker containers give you an ability that virtual machines do not, running different applications at the same time using the same kernel without the need for different operating systems.

Install Docker CE on Ubuntu 22.04

Prerequisites

You need to have Ubuntu 22.04 64-bit installed before you install Docker CE on Ubuntu 22.04.

Install Docker CE on Ubuntu 22.04

You can install Docker CE on Ubuntu 22.04 using any of the methods below. The first method is the recommended one but the second one is also okay if you choose to manually manage upgrades.

The last method is mainly for testing and development environments

Now let’s look at the individual installation method.

Install Docker CE on Ubuntu 22.04 using the repository

First, update the system packages to avoid dependency issues.

sudo apt update

Install curl if not installed:

sudo apt install curl

Add Docker’s official GPG key:

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

Setup a stable repository:

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

Update the system packages again.

sudo apt update

Now install the latest version of Docker.

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

Install Docker CE on Ubuntu 22.04 from .DEB package

Click on the link on Docker Download page.

Download the docker client.

Now change to the path to where you downloaded the package and install using dpkg:

sudo dpkg -i package.deb

Output;

Install using the convenience script

This method installs Docker into development environments quickly without interacting with Ubuntu 22.04. This involves installing the source code by running scripts.

It should be noted that the scripts require root or sudo privileges to run.

Download the latest script from get.docker.com.

curl -fsSL https://get.docker.com -o get-docker.sh

Now install Docker CE on Ubuntu 22.04.

sudo sh get-docker.sh

Output;

itnixpro@itnixpro-VirtualBox:~$ sudo sh get-docker.sh
# Executing docker install script, commit: 93d2499759296ac1f9c510605fef85052a2c32be
+ sh -c apt-get update -qq >/dev/null
+ sh -c DEBIAN_FRONTEND=noninteractive apt-get install -y -qq apt-transport-https ca-certificates curl >/dev/null
+ sh -c curl -fsSL "https://download.docker.com/linux/ubuntu/gpg" | gpg --dearmor --yes -o /usr/share/keyrings/docker-archive-keyring.gpg
+ sh -c echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu focal stable" > /etc/apt/sources.list.d/docker.list
+ sh -c apt-get update -qq >/dev/null
+ sh -c DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends  docker-ce-cli docker-scan-plugin docker-ce >/dev/null
E: Sub-process /usr/bin/dpkg returned an error code (1)

Confirm installation of Docker CE

  • Check if Docker is installed:
docker version
  • Confirm you have been able to install Docker CE on Ubuntu 22.04 and is working by running the default hello word image
 sudo docker run hello-world

Output;

itnixpro@itnixpro-VirtualBox:~$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:10d7d58d5ebd2a652f4d93fdd86da8f265f5318c6a73cc5b6a9798ff6d2b2e67
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/

Uninstall the Docker Engine

  1. Uninstall the Docker Engine, CLI, and Containerd packages: $ sudo apt purge docker-ce docker-ce-cli containerd.io
  2. Now delete images, containers, volumes, or customized configuration files on your host that are not automatically removed. $ sudo rm -rf /var/lib/docker $ sudo rm -rf /var/lib/containerd

Conclusion

You have succefully maneged to iInstall Docker CE on Ubuntu 22.04. I hope the tutorial was simple to follow. More information about installation, post-installation and development with Docker is found in Docker Docs

More interesting tutorials

Install Bacula Server with MariaDB on Ubuntu 22.04

Install Thunderbird mail client on Ubuntu 22.04

Install Java 18 in Ubuntu 22.04

Android Developer | Linux | Technical Writer | Backend Developer

Leave a Comment