What is docker and How to install it in ubuntu 20.04

What is Docker?

Docker is the widely used engine to manage and run container modules in Linux. A container is a software package that holds all the dependencies and code to run that application and an application In run time is called a container.

Why do we need docker?

Developers always face situations where the application code works in one system but not in another the main reason is that the dependencies/versions of both environments will be different. In order to solve this issue we need docker which packs all the application code, libraries, system tools etc and creates an image of it using this image we can run and deploy the application in any environment. Also, docker helps in devops for setting up CI/CD we can pack and ship the image to any environment and runs our application.

How does Docker work?

Docker works by using containerization technology, which allows developers to package applications and their dependencies into containers. A Docker container is a lightweight, standalone, and executable package that includes everything needed to run an application, including code, libraries, and system tools. Docker uses a layered file system and copy-on-write technology to make the containers highly efficient and lightweight.
We can create our own docker images using docker file or docker-compose.

What are Docker Images, Containers, and Registries?

Docker images are the building blocks of Docker containers. A Docker image is a read-only template that includes the application code, libraries, and system tools needed to run the application.
Docker containers are created from Docker images and can be started, stopped, and deleted as needed. Docker is a tool developed to run containers.
Docker registries are repositories for storing and sharing Docker images. The most popular Docker registry is Docker Hub, which is a public repository for Docker images.

I know that these information may not be enough for understanding the concept of docker but hope you have got a basic understanding of docker and it’s working.

How to install docker in our system?

We can install docker from the ubuntu repo but the problem is that the ubuntu repo may don’t contain the latest version of docker so we are going to install docker from the official docker repo in Ubuntu 20.04.

Step 1: Initially we need to update the existing list of packages.

sudo apt update

Step 2: Next step is to install some dependent packages before the installation of docker

sudo apt-get install curl apt-transport-https ca-certificates software-properties-common

Installing depended packages inorder to run docker.

This command will install the following packages.

curl –to transfer data.
apt-transport-https-– helps the package manager to transfer files over HTTPS.
ca-certificates–used to check the security certificate between web browser and system.
software-properties-common— it is used to provide useful scripts for adding and removing personal package Archives(ppa).

Step 3: Next step is to add the GPG keys.

The Docker installation package available in the official Ubuntu repository may not be the latest version. so in order to get the latest version of docker, we need to download it from the official docker repo for that

GPG keys allow you to sign and encrypt your data so you need to Add the GPG key by entering the following command.

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Installing GPG keys for encrypting data

Step 4: Next we need to add the docker repo in order to install docker from its official repository for that run this command.

echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
To add docker repo from the official docker hub

Step 5: Now the repo is added you can check whether Docker is installed or not and to make sure that you are installing the docker from the official docker repo using the apt-cache policy command ie.Update the repo again using the command

sudo apt update

apt-cache policy docker-ce

Image used to check whether Docker is installed or not

Please pay attention to the output above as it is not installed the status shows none also you can see that it is downloading packages from download.docker.com.

Step 6: The final step is to install the docker using apt install command

sudo apt install docker-ce -y

Step 7: You can verify the installation of docker using

docker -v

This image is used to show the docker version

To uninstall docker from ubuntu use the below command

apt uninstall docker-ce -y

In this blog, we have learned how to install docker in ubuntu 20.04.

Please visit our blog to learn more about working with docker How to run docker images as a container

Leave a Reply

Your email address will not be published. Required fields are marked *