With each passing day popularity of Docker is also increasing. Docker is an open-source tool and is available for all operating systems. In this tutorial, we will understand how we can install Docker on Ubuntu. So let’s get started.
Install docker on ubuntu
In this session, we will understand how to install docker on an ubuntu system.
Install docker on ubuntu by setting up docker repositories
There are many ways to install Docker on Ubuntu, and In this tutorial, I will explain how to install Docker by setting up the docker repositories.
Before installing Docker on Ubuntu, it is recommended to uninstall any old version of docker,docker.io or docker-engine. Type the below command to remove old docker packages.
sudo apt-get remove docker docker-engine docker.io containerd runc Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package docker-engine
Once all the docker packages are uninstalled, let’s proceed further and update all ubuntu packages.
sudo apt-get update Get:1 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB] Hit:2 http://archive.ubuntu.com/ubuntu focal InRelease Get:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB] Get:4 http://archive.ubuntu.com/ubuntu focal-backports InRelease [101 kB] Fetched 328 kB in 13s (24.4 kB/s) Reading package lists... Done
Now install other packages to allow apt
to use of a repository over HTTPS
sudo apt-get install apt-transport-https ca-certificates curl gnupg lsb-release Reading package lists... Done Building dependency tree .................<supressed o/p>............. .................<supressed o/p>............. Do you want to continue? [Y/n] y Get:1 http://archive.ubuntu.com/ubuntu focal-updates/main amd64 distro-info-data all 0.43ubuntu1.5 [4656 B] .................<supressed o/p>............. .................<supressed o/p>............. Setting up gpg-wks-server (2.2.19-3ubuntu2.1) ... Setting up gpg-wks-client (2.2.19-3ubuntu2.1) ... Setting up gnupg (2.2.19-3ubuntu2.1) ... Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
press y to continue the installation.
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
Use the following command to set up the 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
and update all ubuntu packages by typing the below command.
sudo apt-get update Get:1 https://download.docker.com/linux/ubuntu focal InRelease [52.1 kB] Hit:2 http://archive.ubuntu.com/ubuntu focal InRelease Get:3 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages [10.6 kB] Hit:4 http://security.ubuntu.com/ubuntu focal-security InRelease Hit:5 http://archive.ubuntu.com/ubuntu focal-updates InRelease Hit:6 http://archive.ubuntu.com/ubuntu focal-backports InRelease Fetched 62.7 kB in 12s (5370 B/s) Reading package lists... Done
Finally, Install Docker and docker-cli, and other docker packages.
sudo apt-get install docker-ce docker-ce-cli containerd.io Reading package lists... Done Building dependency tree Reading state information... Done .................<supressed o/p>............. .................<supressed o/p>............. invoke-rc.d: could not determine current runlevel invoke-rc.d: policy-rc.d denied execution of start. Processing triggers for systemd (245.4-4ubuntu3.7) ... Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
Awesome, we have installed all the necessary docker packages. Now let’s start the docker service by typing the below command:
sudo service docker start * Starting Docker: docker [ OK ] [email protected]:~#
Verify if the docker service starts.
sudo service docker status * Docker is running
Finally, pull a hello-world docker image and verify the output.
docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 2db29710123e: Pull complete Digest: sha256:cc15c5b292d8525effc0f89cb299f1804f3a725c8d05e158653a563f15e4f685 Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/
Awesome you have successfully installed docker in your system. You can check my other blogs to
Conclusion
I hope this tutorial helps you to install Docker on the ubuntu system. Please do let me know if you face any issues while installing Docker.