Install docker on Linux (Ubunutu 20 LTS)

Docker provides the ability to package and run an application in a loosely isolated environment called a container. The isolation and security allow you to run many containers simultaneously on a given host. Containers are lightweight because they don’t need the extra load of a hypervisor, but run directly within the host machine’s kernel.

Docker installation steps :

  • First update the system
sudo apt update  
  • Install prerequisite packages which let apt use packages over HTTPS
sudo apt install apt-transport-https \
    ca-certificates curl \
    software-properties-common  
  • Add official GPG keys
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | \
    sudo apt-key add -  
  • Add the docker repository
sudo add-apt-repository \
    "deb [arch=amd64] \
    https://download.docker.com/linux/ubuntu focal stable"  
  • Update newly added repository
sudo apt update  
  • Now installing docker engine
sudo apt-get install docker-ce docker-ce-cli containerd.io
  • Add the docker daemon to run on startup
sudo systemctl status docker  

The output will look like this


  • Testing the docker engine
sudo docker run hello-world

Output :

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:e7c70bb24b462baa86c102610182e3efcb12a04854e8c582838d92970a09f323
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 an informational message and exits.

Runnning the docker command without sudo :

  • First Add your username into the docker group
sudo usermod -aG docker ${USER}
  • Now to apply the changes login to the user and confirm that user will be added to the docker group by
su - ${USER}
id -nG

Thats it, now Log-out and re-login then run below command

docker run hello-world