Let me walk you through the steps to install docker on Ubuntu today. Since I was installing it on my system, I decided to write a tutorial to visually guide you through it so you can ensure you have docker up and running by the end of this guide.
Before we begin to install docker on our Ubuntu system, let met get you familiarized with what docker is. If you want to skip to the installation steps, click here.
What is Docker?
The Docker engine is open-source software designed to build and run applications in isolated environments known as containers.
It uses OS-level virtualization to run the applications. This is similar to virtual machines but the Docker engine offers a more resource-friendly and portable environment to our processes.
Developed by Docker.Inc under the Apache License, the Docker engine hosts images, networks, and containers through a server-side daemon process. Since its initial release in 2013, Docker has grown massively in demand and reputation.
Steps to Install Docker on Ubuntu
To install the Docker engine on your Ubuntu system, you need to have a 64-bit version of Ubuntu. The Docker Engine is supported only on the systems with the following architectures.
- s390x (IBM Z)
- ppc64le (IBM Power)
1. Clean your system of previous docker installs
Before we install the Docker engine on our system, we need to remove any previous installations of docker. To do so, enter the following command in your terminal.
sudo apt --purge remove docker docker-engine docker.io containerd runc
This will remove any previous installations of docker on your system if present. It is okay if the command says that none of these packages were installed.
In case you ever had an older installation of Docker on your system, the contents of /var/lib/docker/ have been retained. This includes any images, networks, or containers.
If you also wish to delete all the settings from your previous installs, you can delete them using the below command.
sudo rm -rf /var/lib/docker
This will delete the Docker library on your system with all the files it contains. Now we are ready to set up the installation of the Docker engine on our machine.
2. Setting up the Docker Repository on your Ubuntu machine
Let’s move on to installing the Docker engine on your system.
There are three methods to install the Docker engine on Ubuntu:
- Using the Docker repository (recommended)
- Manually installing the Docker package
- Using the automated convenience scripts.
In this tutorial, we will use the recommended method of installation using the Docker repository. To do so, we need to first update the apt repository. This can be done using this command.
sudo apt update
Next, we will install the necessary packages to allow the apt command to use a repository over the HTTPS protocol. These commands will install all the required packages for the task.
sudo apt install apt-transport-https ca-certificates curl software-properties-common
Now, we will add the official GPG key by Docker to our repository using the following command.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
Next, we will verify if we have the correct key having the fingerprint:
9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88
We will do so by searching for the last 8 digits of the fingerprint in our repository with this command.
sudo apt-key fingerprint 0EBFCD88
If all steps were followed correctly, you should see the above output confirming the key. Now we will set up the stable repository for our Docker engine.
Note that you can set up a nightly or test repository by adding the word ‘nightly’ or ‘test’ after ‘stable’ in the command given below.
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
Notice that the command says [arch=amd64]. This is the repository for the x86_64 / amd64 architecture systems. If your system has a different architecture, make sure to replace the architecture name accordingly. Once we add the repository, we can now proceed to install the Docker engine on our system.
3. Installing the Docker engine
To install the latest version of the Docker engine on our machine, we first update our repositories again as we did earlier. Next, we use the apt command to install the Docker engine on our system as follows.
sudo apt install docker-ce docker-ce-cli containerd.io
You should see the above output which confirms the installation of the Docker engine on your system. Note that if you have multiple repositories set up and you use the apt command without specifying, the command will install the highest available version of the program on your machine. This can cause issues related to the program’s stability.
This can be managed by specifying the version of the program which you wish to install on your system. To install a specific version of the Docker engine, you need to first list the available versions of the program in your repository as follows.
Now, we install the desired version of the program by replacing <VERSION_STRING> in the following command by the version name, for example 5:19.03.9~3-0~ubuntu-bionic.
sudo apt install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io
This will install your desired version of the Docker engine on your system.
4. Testing your Docker install on your Ubuntu machine
We will verify the installation by running the hello-world image in the Docker engine. To do so, we use this command in our terminal
This will download the hello-world test image and run it in a container before exiting. Once the verification is done, your Docker engine installation is complete. Now you can add users and start working with the program.
When you need to update your installation of the Docker engine, just run the apt update command. Then you need to follow the installation process again, choosing the newer version which you just downloaded.
The Docker engine is a powerful tool for building and testing applications in isolated environments. With the high-performance docker daemon managing the containers, images and networks, the Docker engine is widely preferred by developers across the world.
We hope that this tutorial was able to help you install the Docker engine on your Ubuntu system. If you have any comments, queries or suggestions, feel free to reach us in the comments below.