In this tutorial, we will learn how to install docker on Ubuntu Linux.
Install docker using the repository:
For this, first set up the repository. Use the following command.
sudo apt-get update
sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release
Now, add docker's GPG key
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
Now give sufficient permission
sudo chmod a+r /etc/apt/keyrings/docker.gpg
In order to set up the repository, use the following command
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Now for installing Docker use the following command, which will install the latest docker.
sudo apt-get update & sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
Install Docker using .deb package:
If we might have a problem with installing the docker with the above or wants to install a specific version of the docker then using .deb package is a good solution.
Download the desired version of .deb from here
In order to test the ubuntu version use the following command
lsb_release -a
we can get the output as below
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.3 LTS
Release: 20.04
Codename: focal
Here, the codename is focal so We chose the same as above. Then browse to pool/stable/, choose amd64, armhf, arm64, or s390x, and download the .deb file
In order to test the CPU available use the following command
lscpu
Go to the download folder and execute the deb package using the following command
sudo dpkg -i docker-ce-cli_18.09.0_3-0_ubuntu-bionic_amd64.deb
Note: make sure to use your own version of the .deb package. Now start the docker
Now, we successfully install docker.
Check the Docker Version:
docker --version
Uninstall Docker:
Uninstall docker, CLI, Containerd, and Docker Compose packages using the following command
sudo apt-get purge docker-ce docker-ce-cli containerd.io docker-compose-plugin
Now, delete all images, containers, and volumes
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd