How to Install Docker on Ubuntu 20.04
Choose a different version or distribution
Introduction
Before we begin talking about how to install Docker on Ubuntu 20.04 OS, let’s briefly understand – What is Docker?
Docker is a popular open-source platform that simplifies the process of creating, deploying, and running applications using containers. With Docker, developers can package their applications and all their dependencies into a single unit called a container.
These containers are lightweight, portable, and isolated, ensuring that applications run consistently across different environments. Docker allows for efficient resource utilization, faster deployment, and scalability, making it an essential tool for modern application development and deployment.
You’ll install Docker on Ubuntu 20.04 (CE) in this tutorial. We will also address a few FAQs on how to install Docker on Ubuntu 20.04.
Advantages of Docker
- Portability: Docker enables applications to run consistently across different environments, ensuring compatibility and eliminating "it works on my machine" issues.
- Efficiency: Containers are lightweight, enabling efficient resource utilization and faster deployment times.
- Scalability: Docker allows easy scaling of applications, both vertically and horizontally, to meet changing demands.
- Isolation: Containers provide isolation between applications, preventing conflicts and enabling greater security.
- Collaboration: Docker simplifies collaboration by allowing developers to share and distribute applications with all their dependencies, ensuring consistent and reproducible environments.
Prerequisites to Install Docker on Ubuntu 20.04
- Ubuntu 20.04 64-bit operating system
- A user account with sudo privileges
- Command-line / terminal
Step 1 – Uninstall Old Version of Docker
It is highly important to remove any default Docker packages from the system before starting the installation process. Execute the below commands to remove unnecessary Docker versions.
sudo apt purge docker-ce
sudo apt autoremove
Step 2 – Install Docker on Ubuntu 20.04
1) At first, update the package list and install all the necessary dependencies.
sudo apt update
2) Next, you will install a few prerequisite packages which will allow apt
to use packages over HTTPS:
sudo apt install apt-transport-https ca-certificates curl software-properties-common
3) Now, add the GPG key for the official Docker repository to your system.
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
4) After that, add the Docker repository to APT sources.
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
5) Now, update the package database with the Docker packages from the newly added repo.
sudo apt update
6) To make sure you are installing from the official Docker repo instead of the default Ubuntu repo run the following command.
apt-cache policy docker-ce
7) First list the available versions in the Docker repository to install a specific version.
apt list -a docker-ce
8) To install a specific version, example 19.03.12
you can type the following:
sudo apt install docker-ce=5:18.09.7~3-0~ubuntu-bionic
9) Docker installation is done now. Check if it is running.
sudo systemctl status docker
10) The output will look something like this:
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2020-08-07 17:00:41 UTC; 17s ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 24321 (dockerd)
Tasks: 8
Memory: 46.4M
CGroup: /system.slice/docker.service
└─24321 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Installing Docker gives Docker service (daemon) along with the docker
command-line utility, or the Docker client.
FAQs to Install Docker on Ubuntu 20.04
What are the system requirements for installing Docker on Ubuntu 20.04?
Ubuntu 20.04 requires a 64-bit version with a compatible kernel and at least 2 GB of RAM to install Docker.
Can I install Docker on Ubuntu 20.04 without root access?
Yes, you can install Docker on Ubuntu 20.04 without root access by adding your user to the docker
group. Remember to log out and log back in for the changes to take effect.
How can I verify if Docker is successfully installed on Ubuntu 20.04?
You can run the command docker --version
in the terminal. If Docker is installed correctly, it will display the version number.
How do I start and stop the Docker service on Ubuntu 20.04?
You can start and stop the Docker service on Ubuntu 20.04 using the following commands: sudo systemctl start docker
to start and sudo systemctl stop docker
to stop.
How can I manage Docker as a non-root user on Ubuntu 20.04?
To manage Docker as a non-root user on Ubuntu 20.04, add your user to the docker
group using the command sudo usermod -aG docker your_username
. Then, log out and log back in for the changes to take effect.
How do I pull and run a Docker image on Ubuntu 20.04?
Use the docker pull
command followed by the image name to pull a Docker image. To run the image, execute docker run image_name
.
How can I remove Docker from Ubuntu 20.04?
To remove Docker from Ubuntu 20.04, use the command sudo apt-get purge docker-ce docker-ce-cli containerd.io
. This will remove Docker and its associated dependencies.
Conclusion
We hope this detailed tutorial helped you understand how to install Docker on your Ubuntu 20.04 machine. To learn more about Docker installation for Ubuntu, check out the official Docker install documentation.
If you have any queries, please leave a comment below, and we’ll be happy to respond to them for sure.