How To Install Docker On Ubuntu 22.04

How to install Docker Community Edition

In this brief tutorial, we’ll walk through installing Docker Community Edition (version 20.10.18) on Ubuntu 22.04, using Docker’s official repositories for a straightforward setup.

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]
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

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
. . .
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.

Conclusion

In this guide, we’ve walked through the steps to successfully install Docker on Ubuntu 22.04, setting the foundation for containerized applications on your system. With Docker up and running, you’re ready to start building, deploying, and managing applications with greater efficiency and flexibility. Whether you’re looking to develop in isolated environments or streamline your deployment pipeline, Docker offers a powerful toolset for modern development. Enjoy your journey into containerization, and explore the many resources Docker provides to take full advantage of its capabilities on Ubuntu 22.04!

(Visited 190 times, 1 visits today)

You may also like