How to install Docker and run images on Ubuntu 21.04

To Install Docker and Run Images on Ubuntu 21.04

Introduction:

Docker is an application that simplifies the process of managing applications, as it provides OS-level virtualization to deliver software in packages called containers. Containers are isolated and contain their own software.

Installation Procedure:

Step 1: Check the OS version by using the following command

linuxhelp@linuxhelp:~$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 21.04
Release:	21.04
Codename:	hirsute

Step 2: Login as root user by using the following command

linuxhelp@linuxhelp:~$ sudo -s
[sudo] password for linuxhelp:

Step 3: Changing to the home directory

root@linuxhelp:/home/linuxhelp# cd ~

Step 4: Updating the packages

root@linuxhelp:~# apt update
Hit:1 http://in.archive.ubuntu.com/ubuntu hirsute InRelease
Hit:2 http://in.archive.ubuntu.com/ubuntu hirsute-updates InRelease
Hit:3 http://in.archive.ubuntu.com/ubuntu hirsute-backports InRelease      
Get:4 http://security.ubuntu.com/ubuntu hirsute-security InRelease [110 kB]
Get:5 http://security.ubuntu.com/ubuntu hirsute-security/main amd64 DEP-11 Metadata [9,668 B]
Get:6 http://security.ubuntu.com/ubuntu hirsute-security/universe amd64 DEP-11 Metadata [5,700 B]
Fetched 126 kB in 2s (69.0 kB/s)                      
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
161 packages can be upgraded. Run 'apt list --upgradable' to see them.

Step 5: Installing prerequisites packages

root@linuxhelp:~# apt install apt-transport-https ca-certificates curl software-properties-common
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
software-properties-common is already the newest version (0.99.10).
software-properties-common set to manually installed.
ca-certificates is already the newest version (20210119ubuntu0.21.04.1).
ca-certificates set to manually installed.
The following NEW packages will be installed:
  apt-transport-https curl
0 upgraded, 2 newly installed, 0 to remove and 161 not upgraded.
Need to get 175 kB of archives.
After this operation, 596 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://in.archive.ubuntu.com/ubuntu hirsute-updates/universe amd64 apt-transport-https all 2.2.4ubuntu0.1 [4,776 B]
Get:2 http://in.archive.ubuntu.com/ubuntu hirsute-updates/main amd64 curl amd64 7.74.0-1ubuntu2.3 [170 kB]
Fetched 175 kB in 0s (581 kB/s)
Selecting previously unselected package apt-transport-https.
(Reading database ... 189713 files and directories currently installed.)
Preparing to unpack .../apt-transport-https_2.2.4ubuntu0.1_all.deb ...
Unpacking apt-transport-https (2.2.4ubuntu0.1) ...
Selecting previously unselected package curl.
Preparing to unpack .../curl_7.74.0-1ubuntu2.3_amd64.deb ...
Unpacking curl (7.74.0-1ubuntu2.3) ...
Setting up apt-transport-https (2.2.4ubuntu0.1) ...
Setting up curl (7.74.0-1ubuntu2.3) ...
Processing triggers for man-db (2.9.4-2) ...

Step 6: Adding GPG key for Docker repo

root@linuxhelp:~# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)).
OK

Step 7: Adding Docker repo to APT resource

root@linuxhelp:~# add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable" 

Repository: 'deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable'
Description:
Archive for codename: focal 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-hirsute.list
Adding disabled deb-src entry to /etc/apt/sources.list.d/archive_uri-https_download_docker_com_linux_ubuntu-hirsute.list
Get:1 https://download.docker.com/linux/ubuntu focal InRelease [57.7 kB]
Get:2 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages [11.6 kB]   
Hit:3 http://in.archive.ubuntu.com/ubuntu hirsute InRelease                           
Hit:4 http://in.archive.ubuntu.com/ubuntu hirsute-updates InRelease
Hit:5 http://in.archive.ubuntu.com/ubuntu hirsute-backports InRelease
Hit:6 http://security.ubuntu.com/ubuntu hirsute-security InRelease
Fetched 69.3 kB in 1s (64.4 kB/s)
Reading package lists... Done

Step 8: To install from Docker repo instead of Ubuntu repo

root@linuxhelp:~# apt-cache policy docker-ce
docker-ce:
  Installed: (none)
  Candidate: 5:20.10.9~3-0~ubuntu-focal
  Version table:
     5:20.10.9~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages

Step 9: Installing Docker by using the following command

root@linuxhelp:~# 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-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-el 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 161 not upgraded.
Need to get 100 MB of archives.
After this operation, 434 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 https://download.docker.com/linux/ubuntu focal/stable amd64 containerd.io amd64 1.4.11-1 [23.7 MB]
Get:2 http://in.archive.ubuntu.com/ubuntu hirsute/universe amd64 pigz amd64 2.6-1 [63.6 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu hirsute/main amd64 liberror-perl all 0.17029-1 [26.5 kB]
Get:4 http://in.archive.ubuntu.com/ubuntu hirsute/main amd64 git-man all 1:2.30.2-1ubuntu1 [931 kB]
Setting up libslirp0:amd64 (4.4.0-1ubuntu0.1) ...

Step 10: Access and Download images from Docker Hub

root@linuxhelp:~# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
2db29710123e: Pull complete 
Digest: sha256:37a0b92b08d4919615c3ee023f7ddb068d12b8387475d64c622ac30f45c29c51
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/

By Installation of Docker and run images on Ubuntu 21.04 comes to an end

Tag : Docker Ubuntu
FAQ
Q
Does Docker support Integrate development tools?
A
Docker works with all development tools you use including VS Code, CircleCI, and GitHub.
Q
Does Docker packages run in the cloud?
A
Docker image runs in any environment from on-premises Kubernetes to AWS ECS, Azure ACI, Google GKE, and more.
Q
Why is Docker so fast than VM?
A
Docker is faster than virtual machines.
Because Dockerized apps are that they use resources from the host system in a more efficient manner.
Q
What is a container in Docker?
A
Docker delivers software in packages called containers, which is called docker image.
Q
What does docker mean?
A
Docker is an open-source containerization platform as a service.