Docker doesn’t need any introduction now, it is a popular and free-to-use container solution that has established itself very well in the field of container-based applications. Here we will learn the best way to install Docker on Ubuntu Hirsute 21.04, Ubuntu Groovy 20.10, Ubuntu Focal 20.04 (LTS), and Ubuntu Bionic 18.04 (LTS).
Being a containerized software solution, Docker offers all functions needed to virtualize applications and operate the containers in an isolated environment from one another, on a host system. A container contains all the resources required to run an application, including the application code, the runtime environment, the system libraries, and the system tools. The system which manages the computer’s resources to the individual containers and ensures their isolation on the host system is called Docker Engine.
Sudo docker run ubuntu bash -c “apt -y update” This will check if an ubuntu image exists locally or not. If it does not exist, it will display “Unable to find image 'ubuntu:latest' locally” message and start pulling it from docker hub. After pulling the image, it will run the apt update command. Jul 30, 2020 I am trying to build Raspberry Pi docker images but I am always having the same error, similar to this one, this one and this one. While running the command apt update as root in a arm32v7/ubuntu:2.
Few key advantages of using Docker container machines:
- Feb 09, 2020 Teams. Connect and share knowledge within a single location that is structured and easy to search.
- While installing docker in your machine, Docker Engine -Community and containerd should be installed as a step. The general command to install this in Ubuntu is. Sudo apt-get install docker-ce.
- Aug 23, 2021 Unless you need the latest Docker Compose version for some specific reasons, you can manage very well with the docker compose version provides by Ubuntu. Docker Compose is available in the universe repository of Ubuntu 20.04 and 18.04 so make sure to enable it first: sudo add-apt-repository universe. You probably won't need it but no harm in.
- Free to use Software
- It requires fewer resources than virtual machines
- Provides Security and isolates the applications from one another and from the host system
- Simple management of many containers via orchestration tools such as Kubernetes
- The availability of containers in the image file makes it easily transferrable to other systems.
- Easy to install and Quickstart
- Best method to install Docker on Ubuntu 20.04 Linux
Best method to install Docker on Ubuntu 20.04 Linux
There are three ways to install Docker on Ubuntu Linux but the best one is by using its official repository. Whereas the two others are SNAP and the base repo.
Hence, here we will show the steps to set up Docker on Ubuntu by adding its official repository which is the best possible way to get the latest stable version. Of course, we can get it via SNAP but due confinement model of Snap you may get issues in connecting to the Docker daemon. Or the system would not be able to recognize the docker daemon running on the host. On the other side, the Docker installation from Ubuntu’s base repo will be an extremely stable one, no doubt, but with no guarantee, you will get the latest one with all new features. Hence, go for the tutorial given below:
1. Add few common packages
There are few packages we require during the setup of Docker on Ubuntu such as adding its repo over HTTPS need package that supports it, curl, and lsb-release to know the version of Linux.
2. Add Docker’s GPG Key
Before adding the repository of Docker, we have to add the GPG key that will ensure the packages we will get to install Docker, are from the authentic source without any kind of alteration.
3. Best way- Add Stable Docker repository on Ubuntu 20.04 or others
Now, on your Ubuntu, paste the following block of command and hit Enter key. It will automatically detect your Ubuntu version to add the corresponding available repository.
4. Run system update
To let the system know that we have recently added a new repository, run a system update command to rebuild the system repo cache.
5. Install Docker Engine on Ubuntu
Finally, run a single command that will install and set up the Docker community version with other required tools on your Ubuntu 20.04 Linux or the one you are using.
6. Test your installation
To know everything has been installed correctly to work with containers, let’s create a simple container image called hello-world.
7. Add your User to the Docker group
By default, to create any Container or to run the Docker command you have to use sudo with it. To remove this, we need to add our current to its group.
That’s it, now the latest version of Docker is on your respective Ubuntu version. From here you can start exploring and creating containers by pulling from DockerHub or creating your own image.
If you are not comfortable with the command line then try out the Docker GUI, here is the article on it: Install Portainer Docker Web GUI or How to install Kitematic on Ubuntu 20.04 LTS…
Docker is an application that simplifies the process of managing application processes in containers. Containers let you run your applications in resource-isolated processes. Containers are similar to Virtual Machines, but are much less resource-intensive, as they only need the absolute minimum to run a particular application, and does not require installation of a separate Operating System.
Let’s look at how we can install and run the Docker on our Ubuntu 18.04 from the Command Line, in a few steps.
Step 1: Retrieve and add the GPG Public Keys
Again, similar to other tutorials regarding package installation on Linux, we always need to get the public key for that package so that we know that it is valid. We can then download the required data and install the package securely.
So let’s get the GPG public key for Docker, which is available at the link:
To download the key, we will use the
wget command from the Terminal.
The downloaded key in my case is called
gpg. After the public key is downloaded, add it to the system keys using
Step 2: Verify Key Fingerprint
Now, to verify that we have added the proper key, we need to check the fingerprint for Docker’s key.
Verify that you now have the key with the fingerprint
9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88, by searching for the last 8 characters of the fingerprint.
You should get an output similar to the below screenshot.
Step 3: Install Required Packages
To set up the Docker repository, our system must have packages which allow us to download files over
HTTPS. So, you need the below packages, which can be downloaded using
Now that we have the necessary requirements, we can now add the Docker repository to our list of sources.
Step 4: Add the Docker Repository to the Sources List
We need to add the Docker source to our list of sources in the system so that any future updates can occur using that source URL when using
We need to modify
Use any text editor (like nano, vi, etc) and open
/etc/apt/sources.list. I will be using
vi editor to edit the file.
Go to the end of the file, and add this line to ensure that we add the repository source link.
Exit the editor, after saving your changes.
Now, we are ready to update the system and install our package!
Step 5: Install Docker on Ubuntu
Now that we have our sources with us, we are ready to install Docker!
It’s simple. First, we update our system and other critical packages. Then, we fetch and install the latest version of Docker from the source. The version that we will be installing is the Docker Community Edition (
docker-ce), so we then install that using
Now, if there aren’t any errors, we will return to our shell prompt, and our install has completed successfully!
Step 6: Verify Docker Installation
If Docker was installed correctly, it would have then automatically started a Docker daemon process. So, we need to use the
systemctl command and check if the docker service has started or not.
If the command works as expected, then you will see an output similar to mine, indicating that the
docker service is active, which means that our installation was indeed successful!
Now, let us now look at how we can configure Docker and run a Docker Container.
Step 7: Execute Docker Commands without sudo
By default, the
docker command can only be run by the root user or by a user in the docker group, which is automatically created during Docker’s installation process. If you attempt to run the
docker command without prefixing it with
sudo or without being in the docker group, you’ll get an output like this:
To avoid typing
sudo for every docker command, add your username to the docker group.
Now, log out and log in again to apply for your user membership successfully on the docker group. Now, there is no need to prefix any docker command using
Step 8: Run a Docker Container
A Docker Container, being similar to a Virtual Machine, also needs an image to work on. There are various images hosted on Docker Hub, Docker’s official website for hosting images. Any image you need can be fetched from this website.
Let us now try to run a simple
hello-world Docker Container, which prints ‘Hello World’ and exits.
1. Fetch the image
To pull the corresponding Docker image, use:
2. Run the container
Now we have the image, using which we can run the Docker container.
To check if we actually have the image, let us list all our Docker images on the system, using
We have the image
hello-world in our system, as expected. Now, let us run the container.
Now, this container will run and print
Hello World, before terminating.
We have thus completed running our first Docker Container!
Similarly, we can fetch and run other interactive Docker Containers as well, thus showing the ease of usage of
docker. To illustrate this, let us show one more example: Installing a Debian image!!
Running a Docker Debian Container
We use the same commands as earlier, using
docker pull debian, to download the image.
Ubuntu Apt Docker-compose
Now, to run this container, since this needs an interactive terminal session, we use:
-it option specifies an interactive terminal session (Combining the
-i and the
Ubuntu Docker Apt-get Not Working
As you can see, we are using a Debian system inside an Ubuntu OS, without the number of resources that a Virtual Machine uses. The image size is itself only 114 MB. Amazing, isn’t it?
Ubuntu Docker Apt Linux
In this tutorial, we showed you how we can install Docker on Ubuntu 18.04 from the Terminal, and how we can fetch images and run Docker containers using the
docker command. I hope this tutorial serves you well and clears any doubts regarding Docker installation or running a Docker container on Ubuntu.