How To Install and Use Docker Engine on Ubuntu 22.04 (Tutorial)

How To Install and Use Docker Engine on Ubuntu 22.04 (Tutorial). In this guide, we introduce Docker, and its advantages then show you how to install and use Docker on Ubuntu 22.04 server.

Docker is a renowned open source software that provides software programs and a uniform and portable platform. Within one year of launch, Docker became the most popular container technology. Docker’s technology is flexible and adaptable to any client environment and is used for developing platforms.

Major large corporations quickly began implementing Docker, and many switched from virtual machines to Docker containers for their application servers. IT firms and banking organizations have also incorporated this new technology. Here, let’s discuss Docker and answer all the questions you may have related to this platform.

Let’s start with how to Install and Use Docker Engine on Ubuntu 22.04.

What is Docker?

Image Source: YouTube

Docker has the ability to package and operate a program in a loosely isolated environment, also known as a container. You execute numerous containers simultaneously on a single host due to the isolation and security it provides. Since the containers are small, you run applications without having to know what has been installed on the host. Sharing containers while working is simple, and you ensure that everyone receives the same container with the same operation.

This platform is an excellent method to build isolated environments and have them scale up or down automatically. Through Docker, IT firms may design, distribute, and operate container applications. The container is a small package containing all the necessary files, bins, and other dependencies.

Additionally, Docker can be used throughout the DevOps cycle, but the deployment phase is its best advantage. Let’s discuss this briefly.

Features of Docker

Docker offers the following powerful features:

Easy and fast configuration

Simple and quick configuration. This allows the quick and effortless deployment of codes.

Isolation

Run applications in a secluded setting, using containers from Docker. Due to the independence of each container, Docker may be able to operate any form of program.

Small Container Size

Makes it possible to share containers in small sizes. Now, the majority of web apps take advantage of this feature, which was quite challenging in the past.

Swarm

For Docker containers, Swarm is a cluster and scheduling tool. It leverages the Docker API on the front end, which enables you to control it with several tools. Pluggable backends are now possible by a group of self organized engines.

Containers to Run on Cloud and AWS

While VMWare cannot be run on Amazon Web Service (AWS), Docker technology enables the use of Docker containers on AWS. The same Docker container runs simultaneously on Cloud and VMWare, owing to Docker’s parallel execution feature.

Services

The Docker services are the state of a container that completes a specified series of tasks. While Swarm schedules them across the nodes, each task mentioned in the services lists should operate independently.

Security Administration

Docker stores secrets in the stores and grants services access to the secrets, including a few crucial engine commands like a secret, inspect and secret create.

Advanced Productivity

Boosts productivity by streamlining technical setup and speeding up application deployment. It also helps the program to run in isolation.

Low costs for infrastructure and maintenance

What is more, Docker helps to launch new and quick solutions while saving money on infrastructure and upkeep of the existing application portfolio, profiting organizations.

What are the Docker Advantages?

Regulating the Code Pipeline

It is mandatory for the coding to pass via several different platforms as it moves from the developer machine to the production area, which may have other surroundings. Docker makes designing and deploying pipeline code standards simpler by establishing an integrated environment for applications.

Scaling the deployment

Due to Docker’s portability and small weight, it also simplifies managing workloads dynamically. In close to real time, it aids in scaling up or down applications and services following changing business requirements.

Container Image

You create a container image with the help of Docker and use that image throughout the entire deployment process. It enables the separation and parallel execution of independent steps. This also significantly shorten the time it takes to go from build to development.

Investment return and cost savings

Docker provides ROI. It lowers costs while increasing profits, especially for big, established businesses that need to provide sustainable revenue in the long run.

We have come to main part of How To Install and Use Docker Engine on Ubuntu 22.04.

How To Install and Use Docker Engine on Ubuntu 22.04

In this section, we explain how to install and use Docker on Ubuntu 22.04 server.

Prerequisites

  • An Ubuntu 22.04 server is installed on your server.
  • A root user or a user with sudo privileges.

Step 1 - Update the System

It is always recommended to update and upgrade all your system packages to the latest version. You update all of them by running the following command.

				
					apt update -y
apt upgrade -y

				
			

After updating all the system packages, you can proceed to add the Docker repository.

Step 2 - Add Docker Repository

The latest version of the Docker package is not available in the Ubuntu 22.04 default repository. So you need to add the Docker official repository to APT.

First, install all the required dependencies using the following command.

				
					apt install apt-transport-https curl gnupg2 ca-certificates software-properties-common -y
				
			

Once all the dependencies are installed, download and add the Docker GPG key with the following command.

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

Next, add the Docker repository to the APT file using the following command.

				
					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" | tee /etc/apt/sources.list.d/docker.list > /dev/null
				
			

Then, update the Docker repository with the following command.

				
					apt update -y
				
			

Once the Docker repository is up to date, you proceed to install Docker.

Step 3 - Install Docker

First, verify the available Docker package with the following command.

				
					apt-cache policy docker-ce
				
			

You should see the Docker package information in the following output.

				
					docker-ce:
Installed: (none)
Candidate: 5:20.10.22~3-0~ubuntu-jammy
Version table:
5:20.10.22~3-0~ubuntu-jammy 500
500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages
5:20.10.21~3-0~ubuntu-jammy 500
500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages
5:20.10.20~3-0~ubuntu-jammy 500
500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages
5:20.10.19~3-0~ubuntu-jammy 500
500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages
5:20.10.18~3-0~ubuntu-jammy 500
500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages
5:20.10.17~3-0~ubuntu-jammy 500
500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages
5:20.10.16~3-0~ubuntu-jammy 500
500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages
5:20.10.15~3-0~ubuntu-jammy 500
500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages
5:20.10.14~3-0~ubuntu-jammy 500
500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages
5:20.10.13~3-0~ubuntu-jammy 500
500 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages

				
			

Now, let’s install the Docker using the following command.

				
					apt install docker-ce -y
				
			

Once the Docker package is installed, you can verify the Docker version using the following command.

				
					docker --version
				
			

You should see the Docker version information in the following output.

				
					Docker version 20.10.22, build 3a2c30b
				
			

Step 4 - Add a User to the Docker Group

By default, only the root user or a user with sudo privileges can run the Docker command. In this case, you can add your user to the Docker group to run all Docker commands without root privileges.

First, create a new user with the following command.

				
					adduser user1
				
			

Set a user password as shown below:

				
					Adding user `user1' ...
Adding new group `user1' (1000) ...
Adding new user `user1' (1000) with group `user1' ...
Creating home directory `/home/user1' ...
Copying files from `/etc/skel' ...
New password:
Retype new password:
passwd: password updated successfully
Changing the user information for user1
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n]

				
			

Next, add a user1 to the Docker group with the following command.

				
					usermod -aG docker user1
				
			

Now, log in with user1 using the following command.

				
					su - user1
				
			

Next, run the Docker help command to see help information.

				
					docker --help
				
			

You will get the following output.

				
					Commands:
attach Attach local standard input, output, and error streams to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
diff Inspect changes to files or directories on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Export a container's filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by default)
search Search the Docker Hub for images
start Start one or more stopped containers
stats Display a live stream of container(s) resource usage statistics
stop Stop one or more running containers
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
top Display the running processes of a container
unpause Unpause all processes within one or more containers
update Update configuration of one or more containers
version Show the Docker version information
wait Block until one or more containers stop, then print their exit codes

				
			

Step 5 - Download or Pull Docker Image

Docker has its own repository hosted on Docker Hub. You can pull any images from the Docker Hub registry using a simple command. Let’s use the docker search command to find all Debian images available on the Docker Hub.

				
					docker search debian
				
			

You should get a list of all images containing the word debian.

				
					NAME DESCRIPTION STARS OFFICIAL AUTOMATED
ubuntu Ubuntu is a Debian-based Linux operating sys… 15421 [OK]
debian Debian is a Linux distribution that's compos… 4542 [OK]
bitnami/minideb A minimalist Debian-based image built specif… 125
neurodebian NeuroDebian provides neuroscience research s… 97 [OK]
ustclug/debian Official Debian Image with USTC Mirror 2
bitnami/debian-base-buildpack Debian base compilation image 2 [OK]
treehouses/debian 2
rancher/debianconsole 1
osrf/debian_arm64 Debian arm64 Base Images 1
osrf/debian_armhf Debian Armhf Base Images 1
eclipse/debian_jdk8_node Node (+ Angular stuff) + JDK8. Debian based 1 [OK]
dokken/debian-11 Debian 11 image for use with kitchen-dokken 1
eclipse/debian_jdk8 Debian, JDK8, Maven 3, git, curl, nmap, mc, … 1 [OK]
corpusops/debian-bare https://github.com/corpusops/docker-images/ 0
dokken/debian-10 Debian 10 image for use with kitchen-dokken 0
corpusops/debian debian corpusops baseimage 0
dokken/debian-9 Debian 9 image for kitchen-dokken 0
mirantis/debian-build-ubuntu-trusty 0
datadog/debian-i386 0
eclipse/debian_jre Base image with JRE, Git, MC, curl, wget 0 [OK]
dokken/debian-7 EOL DISTRO: For use with kitchen-dokken, Bas… 0
treehouses/debian-tags 0
dokken/debian-12 0
mirantis/debian-build-ubuntu-xenial 0
dokken/debian-8 EOL: Debian 8 image for kitchen-dokken 0

				
			

Now, pull the latest version of the Debian image using the following command.

				
					docker pull debian:latest
				
			

You will get the following output.

				
					latest: Pulling from library/debian
32de3c850997: Pull complete
Digest: sha256:c66c0e5dc607baefefda1d9e64a3b3a317e4189c540c8eac0c1a06186fe353a1
Status: Downloaded newer image for debian:latest
docker.io/library/debian:latest
				
			

To verify the downloaded image, run the following command.

				
					docker images
				
			

You should see your Debian image in the following output.

				
					REPOSITORY TAG IMAGE ID CREATED SIZE
debian latest 446440c01886 2 weeks ago 124MB

				
			

Step 6 - Launch a Docker Container

After downloading Docker image, you need to create and run a container from the downloaded image. To create and start the Debian container, run the following command.

				
					docker run -dit debian:latest
				
			

This command will start the container and run it in the background. You verify the running container using the following command.

				
					docker ps
				
			

This will show you the status of the container in the following output.

				
					CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
541271f68338 debian:latest "bash" 6 seconds ago Up 6 seconds keen_lederberg
				
			

Step 7 - Connect to Docker Container

At this point, the Docker container is started and runs in the background. Now, you can use docker exec command to connect to the running container.

				
					docker exec -it 541271f68338 /bin/bash
				
			

You will get into the container as shown below.

				
					root@541271f68338:/#
				
			

Now, you can run any command inside the container. For example, to verify the container operating system version, run the following command.

				
					cat /etc/os-release
				
			

You should see the following output.

				
					PRETTY_NAME="Debian GNU/Linux 11 (bullseye)"
NAME="Debian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
				
			

Next, exit from the container shell with the following command.

				
					root@541271f68338:/# exit
				
			

Step 8 - Manage Docker Container

Docker provides a lot of command line options to manage the Docker container via the command line interface. If you want to stop the running container, run the following command.

				
					docker container stop container-id
				
			

To start the container, run the following command.

				
					docker container start container-id
				
			

If you want to pause the container, run the following command.

				
					docker container pause container-id
				
			

To remove the stopped container, run the following command.

				
					docker container rm container-id
				
			

You can also remove any Docker image using the following command.

				
					docker rmi image-id
				
			

Thank you for reading how To Install and Use Docker Engine on Ubuntu 22.04.

How To Install and Use Docker Engine on Ubuntu 22.04 Conclusion

In this post, we showed you how to install Docker on Ubuntu 22.04. We also explain how to search and download images, run a container and connect to the running container. You can now conclude why Docker is important and becoming popular globally. Understanding Docker aids you to get the most out of your containerized applications since it was created for current DevOps teams.

To explore more of our Docker content, please navigate to this section of our blog.

Avatar for Hitesh Jethva
Hitesh Jethva

I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.

0 0 votes
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x