In this article, we will learn the method to install Docker in Ubuntu. The article will be updated from time to time for the latest versions of Ubuntu. The current tutorial is made with Ubuntu 22.04 in mind. You can install Docker in Ubuntu 22.04 using this tutorial.
Steps to Install Docker in Ubuntu?
Here are the steps to install Docker in Ubuntu or any other Ubuntu-based Linux distros:
1. Verify the Docker GPG
To begin the installation, you first need to add the repository. But before that you need to verify the official Docker PGP with the following command:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
2. Add the Docker Repository
Now, add the official repository to Ubuntu with the following 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
3. Install required dependencies
Install other required dependencies
sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release -y
4. Install Docker
Finally, install Docker
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io -y
5. Add user to Docker group
Add the user to the Docker group
sudo usermod -aG docker $USER
One Command Docker Installation
Instead of typing the commands one by one, you can copy-paste the following to do it in one go:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg && 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 && sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release -y && sudo apt-get update && sudo apt-get install docker-ce docker-ce-cli containerd.io -y && sudo usermod -aG docker $USER
After the above command is pasted in Terminal, docker will be installed on your Ubuntu machine. Now, you can verify your docker installation with the following command:
docker version
If the above command gives you something like the following output. Your docker installation is completed.
Server: Docker Engine - Community
Engine:
Version: 20.10.18
If you don’t see the above output and get some error, please comment down below and I will help you in solving the issue.