In this article we will learn how to install Docker Community Edition (CE) on Ubuntu 22.04 LTS operating system.
Introduction
In today’s fast-paced and dynamic software development landscape, containerization has become a game-changer. Docker, an open-source platform, has revolutionized the way applications are developed, deployed, and managed. In this article, we will explore what Docker is, its key concepts, how it works, and its benefits for developers and operations teams.
What is Docker?
Docker is a containerization platform that allows developers to package applications and their dependencies into lightweight, portable containers. Containers provide an isolated and consistent environment for running applications, ensuring that they work consistently across different environments.
Key Concepts of Docker
- Docker Image: A Docker image is a lightweight, standalone package that contains everything needed to run an application, including the code, runtime, libraries, and dependencies. Images are the building blocks used to create containers.
- Container: A container is an instance of a Docker image. It encapsulates an application and its runtime, ensuring that it runs consistently across various environments. Containers are portable and can be easily moved from one host to another.
- Docker Hub: Docker Hub is a cloud-based registry that hosts a vast collection of Docker images. Developers can use public images from Docker Hub or create and store their custom images privately.
- Dockerfile: A Dockerfile is a text file that contains instructions for building a Docker image. It defines the base image, adds dependencies, sets environment variables, and specifies commands to run when the container starts.
How Docker Works
- Building Docker Images: Developers create Docker images by writing a Dockerfile that defines the steps required to build the image. Docker uses the Dockerfile to create a reproducible image that includes all the necessary components to run the application.
- Running Containers: Once the Docker image is built, it can be used to run containers. Containers are isolated from the host system and other containers, ensuring that applications run consistently without interfering with each other.
- Managing Containers: Docker provides powerful management capabilities for containers. Developers can start, stop, restart, and remove containers with simple commands. Docker also allows scaling applications by running multiple instances of the same container.
Installing Docker On Ubuntu 22.04 LTS
Installing Docker on Ubuntu is a straightforward process using the package manager. Docker provides a script that automates the installation, making it even easier. Here are the steps to install Docker on Ubuntu:
Step 1: Update System Packages
Step 2: Install Required Dependencies
Step 3: Add Docker GPG Key
Step 4: Add Stable Docker Repository
Step 5: Install Docker
Step 6: Start Docker Service
Step 7: Verify Docker Installation
Step 1: Update System Packages
Before installing Docker, it’s a good practice to update the system packages. Open a terminal and run the following command:
$ sudo apt update
Step 2: Install Required Dependencies
Docker requires some dependencies to be installed on your system. Use the following command to install them:
$ sudo apt-get install ca-certificates curl gnupg lsb-release
Output :
ramansah@infodiginet:~$ sudo apt-get install ca-certificates curl gnupg lsb-release
Reading package lists… Done
Building dependency tree… Done
Reading state information… Done
lsb-release is already the newest version (11.1.0ubuntu4).
ca-certificates is already the newest version (20230311ubuntu0.22.04.1).
gnupg is already the newest version (2.2.27-3ubuntu2.1).
gnupg set to manually installed.
The following NEW packages will be installed:
curl
0 upgraded, 1 newly installed, 0 to remove and 174 not upgraded.
Need to get 194 kB of archives.
After this operation, 454 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 curl amd64 7.81.0-1ubuntu1.13 [194 kB]
Fetched 194 kB in 1s (148 kB/s)
Selecting previously unselected package curl.
(Reading database … 207519 files and directories currently installed.)
Preparing to unpack …/curl_7.81.0-1ubuntu1.13_amd64.deb …
Unpacking curl (7.81.0-1ubuntu1.13) …
Setting up curl (7.81.0-1ubuntu1.13) …
Processing triggers for man-db (2.10.2-1) …
Step 3: Add Docker GPG Key
Next, add the Docker GPG key to the system using the following command:
$ sudo mkdir -p /etc/apt/keyrings $ $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Step 4: Add Stable Docker Repository
Add the stable Docker repository to the system, by submitting command line :
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
Step 5: Install Docker
Next step is to install Docker on Ubuntu 22.04 system by submitting command line :
$ sudo apt update
To ensure we will use Docker repository instead of Ubuntu repository is to use the command line below :
$ apt-cache policy docker-ce
Output will be as shown below :
ramansah@infodiginet:~$ apt-cache policy docker-ce docker-ce: Installed: (none) Candidate: 5:24.0.5-1~ubuntu.22.04~jammy Version table: 5:24.0.5-1~ubuntu.22.04~jammy 500 500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages 5:24.0.4-1~ubuntu.22.04~jammy 500 500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages 5:24.0.3-1~ubuntu.22.04~jammy 500 500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages 5:24.0.2-1~ubuntu.22.04~jammy 500 500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages
Installing Docker Community Edition (CE) by submitting command line :
$ sudo apt install docker-ce
Output will be as shown below :
ramansah@infodiginet:~$ sudo apt install docker-ce Reading package lists... Done Building dependency tree... Done Reading state information... Done The following additional packages will be installed: containerd.io docker-buildx-plugin docker-ce-cli docker-ce-rootless-extras docker-compose-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-buildx-plugin docker-ce docker-ce-cli docker-ce-rootless-extras docker-compose-plugin git git-man liberror-perl libslirp0 pigz slirp4netns 0 upgraded, 12 newly installed, 0 to remove and 136 not upgraded. Need to get 118 MB of archives. After this operation, 435 MB of additional disk space will be used. Do you want to continue? [Y/n] Y ... Setting up docker-ce (5:24.0.5-1~ubuntu.22.04~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.9) ... Processing triggers for man-db (2.10.2-1) ... Processing triggers for libc-bin (2.35-0ubuntu3.1) ...

By default, Docker service is automatically started and the process enabled to start on boot. We will verify it by submitting command line below :
$ sudo systemctl status docker $ docker --version
Output will be as shown below :
ramansah@infodiginet:~$ sudo systemctl status docker docker.service - Docker Application Container Engine Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: active (running) since Tue 2023-08-01 13:50:14 WIB; 2min 53s ago TriggeredBy: ● docker.socket Docs: https://docs.docker.com Main PID: 44397 (dockerd) Tasks: 8 Memory: 28.7M CPU: 332ms CGroup: /system.slice/docker.service └─44397 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock Agu 01 13:50:14 infodiginet systemd[1]: Starting Docker Application Container Engine... Agu 01 13:50:14 infodiginet dockerd[44397]: time="2023-08-01T13:50:14.392391431+07:00" level=info msg="Starting up" Agu 01 13:50:14 infodiginet dockerd[44397]: time="2023-08-01T13:50:14.394038708+07:00" level=info msg="detected 127.0.0.53 nam> Agu 01 13:50:14 infodiginet dockerd[44397]: time="2023-08-01T13:50:14.500746321+07:00" level=info msg="Loading containers: sta> Agu 01 13:50:14 infodiginet dockerd[44397]: time="2023-08-01T13:50:14.768832725+07:00" level=info msg="Loading containers: don> Agu 01 13:50:14 infodiginet dockerd[44397]: time="2023-08-01T13:50:14.801315168+07:00" level=info msg="Docker daemon" commit=a> Agu 01 13:50:14 infodiginet dockerd[44397]: time="2023-08-01T13:50:14.801655182+07:00" level=info msg="Daemon has completed in> Agu 01 13:50:14 infodiginet dockerd[44397]: time="2023-08-01T13:50:14.848942062+07:00" level=info msg="API listen on /run/dock> Agu 01 13:50:14 infodiginet systemd[1]: Started Docker Application Container Engine.
ramansah@infodiginet:~$ docker --version Docker version 24.0.5, build ced0996
Conclusion
We have successfully installed Docker on your Ubuntu system. Docker is now ready to be used for containerizing applications and streamlining the deployment process. With Docker, you can take advantage of the benefits of containerization, such as portability, isolation, and scalability, to enhance your software development and deployment workflows. Enjoy using Docker to simplify application deployment and management on your Ubuntu system!