Installing Docker on Linux Systems (Ubuntu)

type
Shorts
date
Mar 21, 2021
description
Docker is an awesome tool for deploying your application to a different platform. In this article, let us install the Docker Community Edition on our local machines for testing this deployment
This guide is mainly to install Docker CE. Also in case you want to install multiple versions of Docker, better follow the official guide ⬆.

Uninstall the Old Version

Make sure you don't have any other version already installed on the machine.
sudo apt-get remove docker docker-engine docker.io containerd runc

Adding docker Official Repository to APT index

By default, apt does not support Docker to be installed/updated since apt is not aware of the official Docker Repository. In order to add the same.
First, Update apt package index.
sudo apt-get update && sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release
Add Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Set up a stable repository.
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

Installing Docker-Engine

Update apt index to latest and install ?Docker Engine
sudo apt-get update && sudo apt-get install docker-ce docker-ce-cli containerd.io
You should now have Docker installed in your machine.
To check the same.
sudo docker run hello-world
You should now get a response like:
notion image
⭐ You might have observed that we used sudo along with docker run to deploy our image to container. This is because no user has been yet added to our Docker group.

Add Current User to Docker Group

Execute the below command to do so:
usermod -a -G docker $USER
⚠ You need to restart the machine (log out & log back in) for the changes to take effect.