How To Install Docker On Ubuntu 22.04

On this short tutorial, we will learn how to install Docker Community Edition version 20.10.18 on Ubuntu 22.04 operating system, we will install Docker by using the Docker’s repositories.

Introduction

Docker technology has been adopted by many organizations both small scale to enterprise class. Docker is an open source technology which manages and automates application deployment by using containers. Containers are created and distributed via images that contain anything to run the application, all dependencies are handled on containers.

In this short tutorial, we will learn how to install and use Docker Community Edition (CE) version 20.10.18 on Ubuntu 22.04. Besides doing the installation, this tutorial will explain how to work with containers and images, and push an image to a Docker Repository.

Docker Installation on Ubuntu 22.04

There are three types Docker installation methods, namely :

  1. Install using the repository
  2. Install using the convenience script
  3. Install from a package

In this short tutorial we will install the latest version of Docker Community Edition by using Docker’s repository.

Prerequisite

Before we start the Docker installation on Ubuntu 22.04, we need to prepare our environment first.

  1. Ubuntu 22.04 system.
  2. Docker Engine is supported on x86_64 (or amd64), armhf, arm64, and s390x architectures.
  3. a sudo non-root user and a firewall.

The Docker installation using repository will be consist of several steps as described below :

A. Set up the repository

  1. Update the system & Install required dependencies
  2. Add Docker’s official GPG key
  3. Set up the repository

B. Install Docker Engine

  • Update the apt package index
  • Install Docker CE on Ubuntu 22.04
  • Verify Docker Engine installation

A. Set Up The Repository

1. Update the system & Install required dependencies

On this stage we will update our Ubuntu 22.04 and install required Docker dependencies. For this purpose we will execute following command line :

$ sudo apt-get update
$ sudo apt-get install ca-certificates curl gnupg lsb-release

Output :

ramans@bckinfo:~$ sudo apt-get update
[sudo] password for ramans: 
Hit:1 http://id.archive.ubuntu.com/ubuntu jammy InRelease                    
Get:2 http://id.archive.ubuntu.com/ubuntu jammy-updates InRelease [114 kB]   
Get:3 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB]
. . .
Get:44 http://security.ubuntu.com/ubuntu jammy-security/universe amd64 DEP-11 Metadata [12,2 kB]              
Get:45 http://security.ubuntu.com/ubuntu jammy-security/universe DEP-11 48x48 Icons [3.602 B]                 
Get:46 http://security.ubuntu.com/ubuntu jammy-security/universe DEP-11 64x64 Icons [7.559 B]                 
Fetched 4.983 kB in 16s (319 kB/s)                                                                            
Reading package lists... Done
ramans@bckinfo:~$ sudo apt-get install ca-certificates curl gnupg lsb-release
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
ca-certificates is already the newest version (20211016).
ca-certificates set to manually installed.
lsb-release is already the newest version (11.1.0ubuntu4).
lsb-release set to manually installed.
gnupg is already the newest version (2.2.27-3ubuntu2.1).
gnupg set to manually installed.
The following additional packages will be installed:
  libcurl4
The following NEW packages will be installed:
  curl
The following packages will be upgraded:
  libcurl4
1 upgraded, 1 newly installed, 0 to remove and 261 not upgraded.
Need to get 484 kB of archives.
After this operation, 453 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://id.archive.ubuntu.com/ubuntu jammy-updates/main amd64 libcurl4 amd64 7.81.0-1ubuntu1.4 [290 kB]
Get:2 http://id.archive.ubuntu.com/ubuntu jammy-updates/main amd64 curl amd64 7.81.0-1ubuntu1.4 [194 kB]      
Fetched 484 kB in 19s (25,1 kB/s)                                                                             
(Reading database ... 197905 files and directories currently installed.)
Preparing to unpack .../libcurl4_7.81.0-1ubuntu1.4_amd64.deb ...
Unpacking libcurl4:amd64 (7.81.0-1ubuntu1.4) over (7.81.0-1ubuntu1.3) ...
Selecting previously unselected package curl.
Preparing to unpack .../curl_7.81.0-1ubuntu1.4_amd64.deb ...
Unpacking curl (7.81.0-1ubuntu1.4) ...
Setting up libcurl4:amd64 (7.81.0-1ubuntu1.4) ...
Setting up curl (7.81.0-1ubuntu1.4) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3) ...

2. Add Docker’s official GPG key

We will do the following command line :

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

3. Set up the repository

Do the following command line :

$ 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

B. Install Docker Community Edition On Ubuntu 22.04 LTS

On this stage, we will install Docker Community Edition On Ubuntu 22.04 LTS by submitting following command lines :

1. Update the apt package index

We will update Ubuntu 22.04

$ sudo apt-get update

Output :

ramans@bckinfo:~$ sudo apt-get update
Get:1 https://download.docker.com/linux/ubuntu jammy InRelease [48,9 kB]                                                     
Hit:2 http://security.ubuntu.com/ubuntu jammy-security InRelease                                                             
Hit:3 http://id.archive.ubuntu.com/ubuntu jammy InRelease
Get:4 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages [7.065 B]
Hit:5 http://id.archive.ubuntu.com/ubuntu jammy-updates InRelease
Hit:6 http://id.archive.ubuntu.com/ubuntu jammy-backports InRelease
Fetched 55,9 kB in 5s (10,2 kB/s)
Reading package lists... Done

2. Install Docker CE on Ubuntu 22.04

We will execute command line :

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

Output :

ramans@bckinfo:~$ sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  docker-ce-rootless-extras docker-scan-plugin git git-man liberror-perl libslirp0 pigz slirp4netns
Suggested packages:
  aufs-tools cgroupfs-mount | cgroup-lite git-daemon-run | git-daemon-sysvinit git-doc git-email git-gui gitk
  gitweb git-cvs git-mediawiki git-svn
The following NEW packages will be installed:
  containerd.io docker-ce docker-ce-cli docker-ce-rootless-extras docker-compose-plugin docker-scan-plugin
  git git-man liberror-perl libslirp0 pigz slirp4netns
0 upgraded, 12 newly installed, 0 to remove and 261 not upgraded.
Need to get 113 MB of archives.
After this operation, 444 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 https://download.docker.com/linux/ubuntu jammy/stable amd64 containerd.io amd64 1.6.8-1 [28,1 MB]
Get:2 http://id.archive.ubuntu.com/ubuntu jammy/universe amd64 pigz amd64 2.6-1 [63,6 kB]    
Get:3 http://id.archive.ubuntu.com/ubuntu jammy/main amd64 liberror-perl all 0.17029-1 [26,5 kB]
Get:4 http://id.archive.ubuntu.com/ubuntu jammy-updates/main amd64 git-man all 1:2.34.1-1ubuntu1.4 [952 kB]   
Get:5 http://id.archive.ubuntu.com/ubuntu jammy-updates/main amd64 git amd64 1:2.34.1-1ubuntu1.4 [3.131 kB]   
Get:6 http://id.archive.ubuntu.com/ubuntu jammy/main amd64 libslirp0 amd64 4.6.1-1build1 [61,5 kB]            
Get:7 http://id.archive.ubuntu.com/ubuntu jammy/universe amd64 slirp4netns amd64 1.0.1-2 [28,2 kB]            
Get:8 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-ce-cli amd64 5:20.10.18~3-0~ubuntu-jammy [41,5 MB]
Get:9 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-ce amd64 5:20.10.18~3-0~ubuntu-jammy [20,4 MB]   
Get:10 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-ce-rootless-extras amd64 5:20.10.18~3-0~ubuntu-jammy [8.386 kB]
Get:11 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-compose-plugin amd64 2.10.2~ubuntu-jammy [6.693 kB]
Get:12 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-scan-plugin amd64 0.17.0~ubuntu-jammy [3.521 kB]
Fetched 113 MB in 7min 13s (261 kB/s)                                                                                     
Selecting previously unselected package pigz.
(Reading database ... 197912 files and directories currently installed.)
Preparing to unpack .../00-pigz_2.6-1_amd64.deb ...
Unpacking pigz (2.6-1) ...
Selecting previously unselected package containerd.io.
Preparing to unpack .../01-containerd.io_1.6.8-1_amd64.deb ...
Unpacking containerd.io (1.6.8-1) ...
Selecting previously unselected package docker-ce-cli.
Preparing to unpack .../02-docker-ce-cli_5%3a20.10.18~3-0~ubuntu-jammy_amd64.deb ...
Unpacking docker-ce-cli (5:20.10.18~3-0~ubuntu-jammy) ...
Selecting previously unselected package docker-ce.
Preparing to unpack .../03-docker-ce_5%3a20.10.18~3-0~ubuntu-jammy_amd64.deb ...
Unpacking docker-ce (5:20.10.18~3-0~ubuntu-jammy) ...
Selecting previously unselected package docker-ce-rootless-extras.
Preparing to unpack .../04-docker-ce-rootless-extras_5%3a20.10.18~3-0~ubuntu-jammy_amd64.deb ...
Unpacking docker-ce-rootless-extras (5:20.10.18~3-0~ubuntu-jammy) ...
Selecting previously unselected package docker-compose-plugin.
Preparing to unpack .../05-docker-compose-plugin_2.10.2~ubuntu-jammy_amd64.deb ...
Unpacking docker-compose-plugin (2.10.2~ubuntu-jammy) ...
Selecting previously unselected package docker-scan-plugin.
Preparing to unpack .../06-docker-scan-plugin_0.17.0~ubuntu-jammy_amd64.deb ...
Unpacking docker-scan-plugin (0.17.0~ubuntu-jammy) ...
Selecting previously unselected package liberror-perl.
Preparing to unpack .../07-liberror-perl_0.17029-1_all.deb ...
Unpacking liberror-perl (0.17029-1) ...
Selecting previously unselected package git-man.
Preparing to unpack .../08-git-man_1%3a2.34.1-1ubuntu1.4_all.deb ...
Unpacking git-man (1:2.34.1-1ubuntu1.4) ...
Selecting previously unselected package git.
Preparing to unpack .../09-git_1%3a2.34.1-1ubuntu1.4_amd64.deb ...
Unpacking git (1:2.34.1-1ubuntu1.4) ...
Selecting previously unselected package libslirp0:amd64.
Preparing to unpack .../10-libslirp0_4.6.1-1build1_amd64.deb ...
Unpacking libslirp0:amd64 (4.6.1-1build1) ...
Selecting previously unselected package slirp4netns.
Preparing to unpack .../11-slirp4netns_1.0.1-2_amd64.deb ...
Unpacking slirp4netns (1.0.1-2) ...
Setting up docker-scan-plugin (0.17.0~ubuntu-jammy) ...
Setting up liberror-perl (0.17029-1) ...
Setting up containerd.io (1.6.8-1) ...
Created symlink /etc/systemd/system/multi-user.target.wants/containerd.service → /lib/systemd/system/containerd.service.
Setting up docker-compose-plugin (2.10.2~ubuntu-jammy) ...
Setting up docker-ce-cli (5:20.10.18~3-0~ubuntu-jammy) ...
Setting up libslirp0:amd64 (4.6.1-1build1) ...
Setting up pigz (2.6-1) ...
Setting up git-man (1:2.34.1-1ubuntu1.4) ...
Setting up docker-ce-rootless-extras (5:20.10.18~3-0~ubuntu-jammy) ...
Setting up slirp4netns (1.0.1-2) ...
Setting up docker-ce (5:20.10.18~3-0~ubuntu-jammy) ...
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/docker.service.
Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /lib/systemd/system/docker.socket.
Setting up git (1:2.34.1-1ubuntu1.4) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3) ...

3. Verify Docker Engine Installation

On this stage, we will verify Docker engine that was installed. We will start up Docker engine service, check its status and downloads a test image and runs it in a container. For this purpose we will do the following command lines :

1. Starting Docker engine.
$ sudo service docker start
$ sudo service docker status

Output :

ramans@bckinfo:~$ sudo service docker start
[sudo] password for ramans: 
ramans@bckinfo:~$ sudo service docker status
● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2022-10-03 13:50:14 WIB; 7min ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 6688 (dockerd)
      Tasks: 8
     Memory: 23.5M
        CPU: 361ms
     CGroup: /system.slice/docker.service
             └─6688 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Okt 03 13:50:11 bckinfo dockerd[6688]: time="2022-10-03T13:50:11.631630936+07:00" level=info msg="scheme \"unix\" not regi>
Okt 03 13:50:11 bckinfo dockerd[6688]: time="2022-10-03T13:50:11.631751975+07:00" level=info msg="ccResolverWrapper: sendi>
Okt 03 13:50:11 bckinfo dockerd[6688]: time="2022-10-03T13:50:11.631860511+07:00" level=info msg="ClientConn switching bal>
Okt 03 13:50:11 bckinfo dockerd[6688]: time="2022-10-03T13:50:11.676961054+07:00" level=info msg="Loading containers: star>
Okt 03 13:50:14 bckinfo dockerd[6688]: time="2022-10-03T13:50:14.099614894+07:00" level=info msg="Default bridge (docker0)>
Okt 03 13:50:14 bckinfo dockerd[6688]: time="2022-10-03T13:50:14.220662626+07:00" level=info msg="Loading containers: done>
Okt 03 13:50:14 bckinfo dockerd[6688]: time="2022-10-03T13:50:14.269157087+07:00" level=info msg="Docker daemon" commit=e4>
Okt 03 13:50:14 bckinfo dockerd[6688]: time="2022-10-03T13:50:14.269435779+07:00" level=info msg="Daemon has completed ini>
Okt 03 13:50:14 bckinfo systemd[1]: Started Docker Application Container Engine.

Check Docker version by submitting command line :

$ docker --version

Outptu :

ramans@bckinfo:~$ docker --version
Docker version 20.10.18, build b40c2f6
2. Test an Image and run it in a container

In this stage we will test to pull an image called as hell-word and run it on local container. This image will print a “Hello from Docker” message. For this purpose we will do the following command line :

$ sudo docker run hello-world

Output :

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

    This command downloads a test image and runs it in a container. When the container runs, it prints a message and exits.

Docker Engine is installed and running. The docker group is created but no users are added to it. You need to use sudo to run

Add a Comment

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