Jul 04, 2021

Installing Docker on Linux Systems (Ubuntu)

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.

shell
sudo apt-get remove docker docker-engine docker.io containerd runc
Loading syntax highlighting...

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.

shell
sudo apt-get update && sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release
Loading syntax highlighting...

Add Docker’s official GPG key:

shell
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
Loading syntax highlighting...

Set up a stable repository.

shell
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
Loading syntax highlighting...

Installing Docker-Engine

Update apt index to latest and install ?Docker Engine

shell
sudo apt-get update && sudo apt-get install docker-ce docker-ce-cli containerd.io
Loading syntax highlighting...

You should now have Docker installed in your machine.

To check the same.

shell
sudo docker run hello-world
Loading syntax highlighting...

You should now get a response like:

⭐ 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:

shell
usermod -a -G docker $USER
Loading syntax highlighting...

⚠ You need to restart the machine (log out & log back in) for the changes to take effect.