How To Install Docker On Ubuntu 20.04 LTS?


Docker is a platform that makes it easier to create, deploy, and use an application using containers. A container contains an application with all parts of it needed such as libraries and other dependencies, and ships it as one package.

Instead of using dedicated resources like virtual machines, docker shares kernel, and other resources of the host system. There are two versions of the Docker: Docker CE(Community Edition), Docker EE (Enterprise Edition). Docker CE is a community-supported version available for free. You can use it for small scale projects or learning.

This article describes how to install and use Docker CE on Ubuntu 20.04 LTS.

Install Docker CE from Docker’s official repository

You can install it from the standard Ubuntu repository but you may not get its latest version. So we will install it from the docker’s official repository.

Setup docker’s official repository

Before we start installing docker we need to set up its official repository, so that we can install and upgrade it easily. Follow the below steps –

First, update the apt package index by using –

sudo apt update

Install the following packages to allow apt to use a repository over HTTPS –

sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-comman

Now add the official GPG key of docker –

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Add the docker stable repository to apt sources, remember to replace the architecture and name of the distribution with your own –

sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"

Now again run the apt update command –

sudo apt update

Install Docker CE

Install the community edition of Docker using the following command –

sudo apt install docker-ce

You can verify the installation by using –

docker --version

Test the docker with hello-world container

You can test the docker by running the hello-world container on Ubuntu 20.04 LTS. Use the following command in your terminal –

sudo docker run hello-world

If the message appears like given in the image that means docker installed in your system is working correctly.

If you want to run docker command without sudo, you need to add your username to the docker group. You can use the following command to add a user to the docker group –

sudo usermod -aG docker {username}

For example –

sudo usermod -aG docker lalit

Now log out and re-login or use the following command to apply the membership of the user.

su {username}

This will ask the password of the current user, enter it. Now you can run the docker command without sudo.

Conclusion

If you want to know more about the options and commands that can be used with the docker then run docker command without any argument. This will display the complete list of options and commands. You can also see its manual page by executing man docker in the terminal.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.