In this blog, we will learn how to install the docker on Ubuntu 20.04 and will see the use of some basic commands of Docker.
Docker is one of the best open-source software which allows us to deploy and run the application very quickly. Docker is a system-friendly software. We can easily run Docker on any type of operating system. Docker provides a platform where applications run in a container that can be easily moved to any system. Docker hub offers a variety of pre-developed images to use. It has repositories where users can easily fetch the images and deploy the application that can later be used by the public.
- Root user or other user with sudo privileges.
- Ubuntu 20.04 operating system.
Installing Docker on Ubuntu
To install the latest Docker, always use official Docker repositories. We can also install the Docker from the Ubuntu repositories, but it may not always be the latest version of Docker. So, always try to use Docker’s repositories.
Enabling Docker repository
To enable the Docker repository, first, we need to update the server’s repositories.
sudo apt update -y sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common -y
Use the below
curl command to import the repository’s GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Add the APT repository of Docker on the server.
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Installing Docker CE
After enabling the Docker repositories, Now you can easily install the Docker version as per your requirement. If you want to install the latest version of docker, run the following commands.
sudo apt update -y sudo apt install docker-ce -y
If you want a particular Docker version, then list down the available Docker version in the Docker repository.
apt list -a docker-ce
The above command will show the list of available Docker versions.
docker-ce/focal 5:20.10.8~3-0~ubuntu-focal amd64 docker-ce/focal 5:20.10.7~3-0~ubuntu-focal amd64 docker-ce/focal 5:20.10.6~3-0~ubuntu-focal amd64 docker-ce/focal 5:20.10.5~3-0~ubuntu-focal amd64 docker-ce/focal 5:20.10.4~3-0~ubuntu-focal amd64 docker-ce/focal 5:20.10.3~3-0~ubuntu-focal amd64
For example, we want to install the Docker version
20.10.8 then you need to enter the following command.
sudo apt install docker-ce=5:20.10.8~3-0~ubuntu-focal
If you want to disable the automatic update of the Docker version. Run the following command.
sudo apt-mark hold docker-ce
After the installation got completed, then enable the Docker service.
systemctl enable docker
Start the Docker service.
systemctl start docker
Check the status of the Docker service is running or not.
systemctl status docker
Executing docker command without sudo
Without administrator privileges, we can’t run the docker commands. To allow the non-root user to run the docker commands without administrator privileges, simply add the user to the docker group. When we install Docker on the server it automatically creates a user and group named as
Run the following command to add the user to the Docker group.
sudo usermod -aG docker $USER
$USER will automatically assign the user name from which you are login on to the server.
To verify, run the docker command without sudo.
docker container run hello-world
hello-world is a test image. Docker will run this image in a container and print a message “Hello from Docker” and then exit from the container.
If you want to upgrade the Docker version, use the below command.
sudo apt update sudo apt upgrade
Always remember that if you uninstall the Docker then it will remove all the containers, volumes, images, and network.
To uninstall the Docker, run the following commands.
sudo apt purge docker-ce sudo apt autoremove
In this tutorial, we have learned how to install Docker’s latest version as well as any specific Docker version on Ubuntu 20.04. Docker is a very big concept. If you want to read detailed information about Docker, then simply click here.
If you guys have any queries or questions, then let me know in the comments section.