Installing and Configuring Docker on Ubuntu 22.04
This is a step-by-step tutorial for installing, configuring and using Docker on Ubuntu 22.04 desktop operating system. If you are searching for steps to install Docker on Ubuntu 22.04 server operating system then you can follow the steps given here and install Docker on your Ubuntu 22.04 server operating system also. Let's get started and install Docker on Ubuntu 22.04 operating system. Steps given here will apply to all the versions of Ubuntu operating system with little change or as it is.
We will first install Docker-CE on Ubuntu 22.04 and after that configure it so that your current user should be able to use Docker as a normal user. By default Docker allows only root users to access the Docker service. You can add any user to the Docker group and after this user will be able to use Docker from his/her login. I will show you all these steps in this tutorial, after completing this tutorial you will be able to install and use Docker on your Ubuntu 22.04 operating system.
We have used the Ubuntu 22.04 installed in the Oracle Virtualbox for this
tutorial, but the steps are the same for all types of Ubuntu 22.04 installation.
Docker is powerful containerization technologies for running packaged
applications inside a Docker container. There are numerous advantages of using
Docker for shipping and deploying your applications on the servers. These days
Docker is very popular among the IT industry for application deployment due to
its simplicity and ease of use.
Docker prerequisites
Docker is a software service and for installation of this service you should have the root or sudo access to your server. If you can using Ubuntu 22.04 Desktop then you can use the terminal and then you can install Docker by going into sudo mode. You also should know the steps to use the apt-get package manager to install software on Ubuntu box. In this tutorial we are giving you step-by-step tutorial to install Docker on your Ubuntu based operating system. After the installation we will also show you to use Docker to run the sample Docker images.
What is Docker?
Docker is very popular container hosting services enabling the engineers to run containerized applications with ease. This tool is very popular and used by millions of deployment instances around the world. Check more at What is Docker?
Installing Docker on Ubuntu 22.04
Now let's get started with the step-step-instruction of installing Docker on Ubuntu 22.04.
Step 1: Login to your Ubuntu 22.04 box and update
First of you have to login to the Ubuntu 22.04 operating system with your username and password. If you are using server version of Ubuntu 22.04 then you can use ssh tool to connect to server using your credentials. After login to the system open the terminal and proceed for the installation of Docker.
Step 2: Update the system
First of all you we have to update our system with latest packages. So, do it by running the following command:
sudo apt update
Here is the screen shot of updating the system:
Output of the sudo apt-get update command
Here is the sample output of the above command:
roseindia@roseindia-VirtualBox:~/Desktop$ sudo apt update [sudo] password for roseindia: Get:1 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB] Hit:2 http://in.archive.ubuntu.com/ubuntu jammy InRelease Get:3 http://in.archive.ubuntu.com/ubuntu jammy-updates InRelease [114 kB] Get:4 http://security.ubuntu.com/ubuntu jammy-security/main i386 Packages [233 kB] Get:5 http://in.archive.ubuntu.com/ubuntu jammy-backports InRelease [99.8 kB] Get:6 http://security.ubuntu.com/ubuntu jammy-security/main amd64 Packages [582 kB] Get:7 http://in.archive.ubuntu.com/ubuntu jammy-updates/main i386 Packages [410 kB] Get:8 http://security.ubuntu.com/ubuntu jammy-security/main Translation-en [122 kB] Get:9 http://security.ubuntu.com/ubuntu jammy-security/main amd64 DEP-11 Metadata [41.5 kB] Get:10 http://security.ubuntu.com/ubuntu jammy-security/main DEP-11 48x48 Icons [13.8 kB] Get:11 http://security.ubuntu.com/ubuntu jammy-security/main DEP-11 64x64 Icons [22.7 kB] Get:12 http://security.ubuntu.com/ubuntu jammy-security/main amd64 c-n-f Metadata [7,632 B] Get:13 http://security.ubuntu.com/ubuntu jammy-security/restricted i386 Packages [25.5 kB] Get:14 http://security.ubuntu.com/ubuntu jammy-security/restricted amd64 Packages [518 kB] Get:15 http://in.archive.ubuntu.com/ubuntu jammy-updates/main amd64 Packages [831 kB] Get:16 http://in.archive.ubuntu.com/ubuntu jammy-updates/main Translation-en [183 kB] Get:17 http://in.archive.ubuntu.com/ubuntu jammy-updates/main amd64 DEP-11 Metadata [97.1 kB]
Step 3: Installing the pre-requisite packages
Now we have to install the pre-requisit package necessary for Docker. Here is the command to install the pre-requisites packages:
sudo apt install apt-transport-https ca-certificates curl software-properties-common
Here is the screen shot of the step:
Output of the command:
roseindia@roseindia-VirtualBox:~/Desktop$ sudo apt install apt-transport-https ca-certificates curl software-properties-common [sudo] password for roseindia: Reading package lists... Done Building dependency tree... Done Reading state information... Done ca-certificates is already the newest version (20211016ubuntu0.22.04.1). ca-certificates set to manually installed. The following packages were automatically installed and are no longer required: libreoffice-ogltrans systemd-hwe-hwdb Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: libcurl4 python3-software-properties software-properties-gtk The following NEW packages will be installed: apt-transport-https curl The following packages will be upgraded: libcurl4 python3-software-properties software-properties-common software-properties-gtk 4 upgraded, 2 newly installed, 0 to remove and 198 not upgraded. Need to get 593 kB of archives. After this operation, 622 kB of additional disk space will be used. Do you want to continue? [Y/n] y Get:1 http://in.archive.ubuntu.com/ubuntu jammy-updates/universe amd64 apt-transport-https all 2.4.8 [1,506 B]
The next step is to add the the GPG key of the official Docker repository in the system so that it will be able to download the files for installation of Docker. Run the following command on your system in terminal:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Following screen shot show the output of above command:
Output of the command:
root@deepak-VirtualBox:/home/roseindia/Desktop# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - OK root@deepak-VirtualBox:/home/roseindia/Desktop#
Step 4: The next step is to update the system to discover Docker packages from the repo, run following command:
sudo apt update
You will get following output:
Here is the output of the above step: 0
root@deepak-VirtualBox:/home/roseindia/Desktop# sudo apt update Hit:1 http://in.archive.ubuntu.com/ubuntu focal InRelease Hit:2 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease Hit:3 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease Hit:4 https://download.docker.com/linux/ubuntu bionic InRelease Get:5 http://security.ubuntu.com/ubuntu focal-security InRelease [107 kB] Fetched 107 kB in 2s (50.3 kB/s) Reading package lists... Done Building dependency tree Reading state information... Done All packages are up to date. root@deepak-VirtualBox:/home/roseindia/Desktop#
Step 5: Now we have to add the Docker repository to APT sources using following command:
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Run the updates with following command:
sudo apt update
This command will update your system to use the newly added Docker repository: 1
Here is the output of the command:
oseindia@roseindia-VirtualBox:~/Desktop$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" Repository: 'deb [arch=amd64] https://download.docker.com/linux/ubuntu jammy stable' Description: Archive for codename: jammy components: stable More info: https://download.docker.com/linux/ubuntu Adding repository. Press [ENTER] to continue or Ctrl-c to cancel. Adding deb entry to /etc/apt/sources.list.d/archive_uri-https_download_docker_com_linux_ubuntu-jammy.list Adding disabled deb-src entry to /etc/apt/sources.list.d/archive_uri-https_download_docker_com_linux_ubuntu-jammy.list Get:1 https://download.docker.com/linux/ubuntu jammy InRelease [48.9 kB] Hit:2 http://in.archive.ubuntu.com/ubuntu jammy InRelease Get:3 https://download.docker.com/linux/ubuntu jammy/stable amd64 Packages [11.2 kB] Hit:4 http://in.archive.ubuntu.com/ubuntu jammy-updates InRelease Hit:5 http://in.archive.ubuntu.com/ubuntu jammy-backports InRelease Hit:6 http://security.ubuntu.com/ubuntu jammy-security InRelease Fetched 60.1 kB in 1s (60.6 kB/s) Reading package lists... Done W: https://download.docker.com/linux/ubuntu/dists/jammy/InRelease: Key is stored in legacy trusted.gpg keyring (/etc/apt/trusted.gpg), see the DEPRECATION section in apt-key(8) for details.
Step 5: Set docker-ce repository ad default 2
Run the following command to use docker-ce repository as default instead to Ubuntu repository:
apt-cache policy docker-ce
Here is the screen shot:
3
Output of the above command is given below:
apt-cache policy docker-ce [sudo] password for roseindia: 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
Step 6: Install Docker on your system
Now are ready to install Docerk from the Docker repo. Run the following command to install Docker on your system: 4
sudo apt install docker-ce
Screen shot of the installation step:
Out of the installation step of Docker: 5
roseindia@roseindia-VirtualBox:~/Desktop$ sudo apt install docker-ce Reading package lists... Done Building dependency tree... Done Reading state information... Done The following package was automatically installed and is no longer required: systemd-hwe-hwdb Use 'sudo apt autoremove' to remove it. The following additional packages will be installed: containerd.io docker-ce-cli 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-scan-plugin git git-man liberror-perl libslirp0 pigz slirp4netns 0 upgraded, 11 newly installed, 0 to remove and 165 not upgraded. Need to get 106 MB of archives. After this operation, 404 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.15-1 [27.7 MB] Get:2 http://in.archive.ubuntu.com/ubuntu jammy/universe amd64 pigz amd64 2.6-1 [63.6 kB] Get:3 http://in.archive.ubuntu.com/ubuntu jammy/main amd64 liberror-perl all 0.17029-1 [26.5 kB] Get:4 http://in.archive.ubuntu.com/ubuntu jammy-updates/main amd64 git-man all 1:2.34.1-1ubuntu1.6 [953 kB] Get:5 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-ce-cli amd64 5:20.10.22~3-0~ubuntu-jammy [41.5 MB] Get:6 http://in.archive.ubuntu.com/ubuntu jammy-updates/main amd64 git amd64 1:2.34.1-1ubuntu1.6 [3,142 kB] Get:7 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-ce amd64 5:20.10.22~3-0~ubuntu-jammy [20.5 MB] Get:8 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-ce-rootless-extras amd64 5:20.10.22~3-0~ubuntu-jammy [8,390 kB] Get:9 http://in.archive.ubuntu.com/ubuntu jammy/main amd64 libslirp0 amd64 4.6.1-1build1 [61.5 kB] Get:10 http://in.archive.ubuntu.com/ubuntu jammy/universe amd64 slirp4netns amd64 1.0.1-2 [28.2 kB] Get:11 https://download.docker.com/linux/ubuntu jammy/stable amd64 docker-scan-plugin amd64 0.23.0~ubuntu-jammy [3,623 kB] Fetched 106 MB in 5s (20.6 MB/s) Selecting previously unselected package pigz. (Reading database ... 195607 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.15-1_amd64.deb ... Unpacking containerd.io (1.6.15-1) ... Selecting previously unselected package docker-ce-cli. Preparing to unpack .../02-docker-ce-cli_5%3a20.10.22~3-0~ubuntu-jammy_amd64.deb ... Unpacking docker-ce-cli (5:20.10.22~3-0~ubuntu-jammy) ... Selecting previously unselected package docker-ce. Preparing to unpack .../03-docker-ce_5%3a20.10.22~3-0~ubuntu-jammy_amd64.deb ... Unpacking docker-ce (5:20.10.22~3-0~ubuntu-jammy) ... Selecting previously unselected package docker-ce-rootless-extras. Preparing to unpack .../04-docker-ce-rootless-extras_5%3a20.10.22~3-0~ubuntu-jammy_amd64.deb ... Unpacking docker-ce-rootless-extras (5:20.10.22~3-0~ubuntu-jammy) ... Selecting previously unselected package docker-scan-plugin. Preparing to unpack .../05-docker-scan-plugin_0.23.0~ubuntu-jammy_amd64.deb ... Unpacking docker-scan-plugin (0.23.0~ubuntu-jammy) ... Selecting previously unselected package liberror-perl. Preparing to unpack .../06-liberror-perl_0.17029-1_all.deb ... Unpacking liberror-perl (0.17029-1) ... Selecting previously unselected package git-man. Preparing to unpack .../07-git-man_1%3a2.34.1-1ubuntu1.6_all.deb ... Unpacking git-man (1:2.34.1-1ubuntu1.6) ... Selecting previously unselected package git. Preparing to unpack .../08-git_1%3a2.34.1-1ubuntu1.6_amd64.deb ... Unpacking git (1:2.34.1-1ubuntu1.6) ... Selecting previously unselected package libslirp0:amd64. Preparing to unpack .../09-libslirp0_4.6.1-1build1_amd64.deb ... Unpacking libslirp0:amd64 (4.6.1-1build1) ... Selecting previously unselected package slirp4netns. Preparing to unpack .../10-slirp4netns_1.0.1-2_amd64.deb ... Unpacking slirp4netns (1.0.1-2) ... Setting up docker-scan-plugin (0.23.0~ubuntu-jammy) ... Setting up liberror-perl (0.17029-1) ... Setting up containerd.io (1.6.15-1) ... Created symlink /etc/systemd/system/multi-user.target.wants/containerd.service → /lib/systemd/syste m/containerd.service. Setting up docker-ce-cli (5:20.10.22~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.6) ... Setting up docker-ce-rootless-extras (5:20.10.22~3-0~ubuntu-jammy) ... Setting up slirp4netns (1.0.1-2) ... Setting up docker-ce (5:20.10.22~3-0~ubuntu-jammy) ... Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/systemd/system/do cker.service. Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /lib/systemd/system/docker .socket. Setting up git (1:2.34.1-1ubuntu1.6) ... Processing triggers for man-db (2.10.2-1) ... Processing triggers for libc-bin (2.35-0ubuntu3.1) ... roseindia@roseindia-VirtualBox:~/Desktop$
Step
7: Checking Status of Docker
After completion of installation of Docker you can check its running status with following command:
sudo systemctl status docker
If Docker is running on your system then it will show following output which shows its running status: 6
Here is the status of the systemctl status docker command:
root@deepak-VirtualBox:/home/roseindia/Desktop# systemctl status docker docker.service - Docker Application Container Engine Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled) Active: active (running) since Sun 2020-08-30 11:10:52 IST; 1min 16s ago TriggeredBy: docker.socket Docs: https://docs.docker.com Main PID: 5174 (dockerd) Tasks: 12 Memory: 36.3M CGroup: /system.slice/docker.service └─5174 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock Aug 30 11:10:51 deepak-VirtualBox dockerd[5174]: time="2020-08-30T11:10:51.756683863+05:30" level=warni> Aug 30 11:10:51 deepak-VirtualBox dockerd[5174]: time="2020-08-30T11:10:51.756707411+05:30" level=warni> Aug 30 11:10:51 deepak-VirtualBox dockerd[5174]: time="2020-08-30T11:10:51.756739632+05:30" level=warni> Aug 30 11:10:51 deepak-VirtualBox dockerd[5174]: time="2020-08-30T11:10:51.757096283+05:30" level=info > Aug 30 11:10:52 deepak-VirtualBox dockerd[5174]: time="2020-08-30T11:10:52.088875824+05:30" level=info > Aug 30 11:10:52 deepak-VirtualBox dockerd[5174]: time="2020-08-30T11:10:52.274728513+05:30" level=info > Aug 30 11:10:52 deepak-VirtualBox dockerd[5174]: time="2020-08-30T11:10:52.768648955+05:30" level=info > Aug 30 11:10:52 deepak-VirtualBox dockerd[5174]: time="2020-08-30T11:10:52.768866151+05:30" level=info > Aug 30 11:10:52 deepak-VirtualBox dockerd[5174]: time="2020-08-30T11:10:52.914268680+05:30" level=info > Aug 30 11:10:52 deepak-VirtualBox systemd[1]: Started Docker Application Container Engine. lines 1-21/
Step 8: Getting Docker information 7
Now you can run the following command to see the docker information:
docker info
Above command will display the Docker information along with your system information. The docker info command will display following message:
8
Here is output of the docker info command :
docker info Client: Debug Mode: false Server: Containers: 0 Running: 0 Paused: 0 Stopped: 0 Images: 0 Server Version: 19.03.12 Storage Driver: overlay2 Backing Filesystem: extfs Supports d_type: true Native Overlay Diff: true Logging Driver: json-file Cgroup Driver: cgroupfs Plugins: Volume: local Network: bridge host ipvlan macvlan null overlay Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog Swarm: inactive Runtimes: runc Default Runtime: runc Init Binary: docker-init
Step 9: Running your First container
Now we will run our first container which is actually distributed at Docker Hub and the image is pulled automatically from the Docker Hub. Here is command to run the "Hello World" Docker container: 9
sudo docker run hello-world
Here is the screen shot:
Output of the command:
docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 0e03bdcc26d7: Pull complete Digest: sha256:7f0a9f93b4aa3022c3a4c147a449bf11e0941a1fd0bf4a8e6c9408b2600777c5 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/
Above command runs the 'hello-world:latest' and displays "Hello from Docker!" on the console along with other information.
Step 10: How to restart Docker?
The systemctl command is used to stop, start and restart the docker service. Here is the command that you can run to restart Docker service on your Ubuntu 20.04: 0
sudo systemctl restart docker
Following is the output of restart command:
Step 11: Checking Docker Container status 1
We have just run the Hello World image in a container and if you type docker ps -l command, Docker will display the list of exited Docker containers as shown below:
Above command gives following output: 2
oseindia@roseindia-VirtualBox:~/Desktop$ sudo docker ps -l CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 01a67c570377 hello-world "/hello" 2 minutes ago Exited (0) 2 minutes ago agitated_knuth roseindia@roseindia-VirtualBox:~/Desktop$
Step 12: Checking Docker images on the system
Since we run the hello world container, the Docker downloaded this image from Docker Hub before running it into container. You can run docker images command to see the list of images:
3
In this tutorial you learned to install Docker on Ubuntu 20.04 operating system then run first "Hello World" Docker container on newly installed Docker.
Here are more tutorials of Docker: