How to Install Docker on Ubuntu 20.04 Using Terminal

Docker is a popular open-source platform that allows developers to automate the deployment of applications inside containers. Containers are lightweight, isolated environments that provide a consistent runtime environment for applications, ensuring that they run smoothly across different systems.

In this blog post, we will discuss the process of installing Docker on Ubuntu 20.04 using the terminal. Ubuntu 20.04 is the latest Long Term Support (LTS) release of Ubuntu, providing stability and security updates for an extended period of time. By following the steps outlined in this article, you will be able to quickly and easily set up Docker on your Ubuntu 20.04 system.

What’s Needed

To install Docker on Ubuntu 20.04 using the terminal, you will need the following:

  • Ubuntu 20.04 installed on your system
  • A user account with sudo privileges
  • An internet connection

Video Tutorial:

What Requires Your Focus?

Before proceeding with the installation process, there are a few important points to keep in mind:

  • Ensure that you are using an up-to-date version of Ubuntu 20.04, as older releases may not be compatible with the latest version of Docker.
  • Make sure that you have sufficient disk space available, as Docker and its dependent packages may require several gigabytes of storage.
  • If you have an existing installation of Docker, it is recommended to remove it before proceeding with the installation process.
  • Be cautious while executing commands with sudo privileges, as they have the potential to make changes to your system.

Option 1: How to Install Docker via the Official Ubuntu Repositories

One of the easiest ways to install Docker on Ubuntu 20.04 is through the official Ubuntu repositories. This method ensures that you have access to the latest stable version of Docker, along with regular updates and security patches.

Steps:

1. Update the package index on your Ubuntu system by running the following command in the terminal:

"`
sudo apt update
"`

2. Install the necessary packages to allow apt to use repositories over HTTPS:

"`
sudo apt install apt-transport-https ca-certificates curl software-properties-common
"`

3. Import the official Docker GPG key using the following command:

"`
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg –dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
"`

4. Add the Docker repository to your system’s sources.list file:

"`
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu focal stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
"`

5. Update the package index again:

"`
sudo apt update
"`

6. Install Docker on Ubuntu 20.04 by running the following command:

"`
sudo apt install docker-ce docker-ce-cli containerd.io
"`

7. Verify that Docker is installed correctly by running the following command:

"`
sudo docker run hello-world
"`

Pros:

– Easy installation process using the official Ubuntu repositories.
– Regular updates and security patches available through the repositories.
– Officially supported by the Docker project.

Cons:

– May not provide the latest bleeding-edge features available in newer Docker versions.
– Limited customization options compared to alternative installation methods.

Option 2: How to Install Docker via the Docker Repository

Another method of installing Docker on Ubuntu 20.04 is by using the Docker repository. This method allows you to have more control over the Docker version and its dependencies, providing the flexibility to choose specific versions or access the latest features.

Steps:

1. Update the package index on your Ubuntu system:

"`
sudo apt update
"`

2. Install the necessary packages to allow apt to use repositories over HTTPS:

"`
sudo apt install apt-transport-https ca-certificates curl software-properties-common
"`

3. Add the Docker repository GPG key using the following command:

"`
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg –dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
"`

4. Add the Docker repository to your system’s sources.list file:

"`
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu focal stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
"`

5. Update the package index again:

"`
sudo apt update
"`

6. Install Docker on Ubuntu 20.04 by running the following command:

"`
sudo apt install docker-ce docker-ce-cli containerd.io
"`

7. Verify that Docker is installed correctly by running the following command:

"`
sudo docker run hello-world
"`

Pros:

– Provides more control over the Docker version and its dependencies.
– Access to the latest features and updates from the Docker project.
– Ability to choose specific versions based on your requirements.

Cons:

– Requires manual configuration of repositories and GPG keys.
– May introduce compatibility issues if the chosen Docker version is not well-tested or stable.

Option 3: How to Install Docker via the Convenience Script

If you prefer a quick and easy installation process, Docker provides a convenient script that automatically installs Docker on your Ubuntu 20.04 system. This method is suitable for users who want a hassle-free installation without manually configuring repositories or keys.

Steps:

1. Download the Docker installation script using the following command:

"`
curl -fsSL https://get.docker.com -o get-docker.sh
"`

2. Run the installation script as root:

"`
sudo sh get-docker.sh
"`

3. Verify that Docker is installed correctly by running the following command:

"`
sudo docker run hello-world
"`

Pros:

– Simple and easy installation process.
– Automatically handles the configuration of repositories and dependencies.
– Suitable for users who prefer a quick and hassle-free installation.

Cons:

– Less control over the Docker version and its dependencies compared to other installation methods.
– Limited customization options during the installation process.

Option 4: How to Install Docker via Snap

Snap is a package management system that provides a straightforward way to install applications on various Linux distributions, including Ubuntu 20.04. By installing Docker using Snap, you can easily manage your Docker installation and receive automatic updates.

Steps:

1. Update the package index on your Ubuntu system:

"`
sudo apt update
"`

2. Install Docker using Snap:

"`
sudo snap install docker
"`

3. Verify that Docker is installed correctly by running the following command:

"`
sudo docker run hello-world
"`

Pros:

– Simplified installation process using the Snap package manager.
– Automatic updates for Docker through the Snap system.
– Sandbox isolation for applications installed via Snap.

Cons:

– May have compatibility issues with specific Ubuntu versions or configurations.
– Limited customization options compared to other installation methods.
– Snap packages may have larger disk footprint due to bundling of dependencies.

Why Can’t I Install Docker via the Official Ubuntu Repositories?

There may be situations where you are unable or prefer not to install Docker using the official Ubuntu repositories. In such cases, here are three alternative solutions to consider:

1. Manual Compilation: You can manually compile and install Docker from the source code available on the Docker GitHub repository. This method provides the highest level of customization and control over the Docker installation process. However, it requires advanced technical skills and may be time-consuming.

2. Using Docker Machine: Docker Machine is a tool that allows you to install Docker on multiple systems using a single command. It provides a convenient way to manage Docker installations on different operating systems, including Ubuntu. By using Docker Machine, you can easily create and manage Docker hosts on Ubuntu 20.04.

3. Using Docker Compose: Docker Compose is a tool that allows you to define and manage multi-container Docker applications. It simplifies the process of running multiple containers together and provides an efficient way to deploy complex applications. By using Docker Compose, you can manage and orchestrate your Docker deployments on Ubuntu 20.04.

Implications and Recommendations

Installing Docker on Ubuntu 20.04 provides several implications and recommendations to consider:

1. Improved Application Portability: Docker’s containerization technology allows applications to run consistently across different systems, eliminating dependency issues and ensuring smooth operation.

2. Enhanced Development Workflow: With Docker, developers can easily create isolated environments for testing and development, ensuring that their applications work as expected in a controlled environment.

3. Efficient Resource Utilization: Containers consume fewer system resources compared to traditional virtual machines, allowing for better utilization of hardware resources and cost savings.

It is recommended to regularly update Docker to the latest version in order to benefit from new features, bug fixes, and security patches. Additionally, it is important to properly secure Docker installations by applying best practices such as using strong passwords, restricting network access, and regularly monitoring container behavior.

The Bottom Line

In this blog post, we discussed various methods of installing Docker on Ubuntu 20.04 using the terminal. We explored the installation process via the official Ubuntu repositories, Docker repositories, convenience script, and Snap package manager. Each method has its own advantages and considerations, depending on your requirements and preferences.

By installing Docker on Ubuntu 20.04, you gain access to a powerful containerization platform that enables efficient application deployment and management. Docker provides immense flexibility and scalability, empowering developers and system administrators to streamline their workflows and enhance application performance.

5 FAQs about Installing Docker on Ubuntu 20.04

Q1: Can Docker run on any version of Ubuntu?

A: Docker can run on most versions of Ubuntu, but it is recommended to use the latest LTS (Long Term Support) release to ensure compatibility and receive regular updates.

Q2: Is it necessary to have sudo privileges to install Docker?

A: Yes, sudo privileges are required to install Docker on Ubuntu as it involves making changes to the system configuration and accessing protected directories.

Q3: Are there any system requirements for installing Docker on Ubuntu 20.04?

A: Docker has minimal system requirements, but it is recommended to have at least 2GB of RAM, 10GB of free disk space, and a 64-bit processor for optimal performance.

Q4: Can Docker containers communicate with each other?

A: Yes, Docker provides networking capabilities that allow containers to communicate with each other through network interfaces and expose ports to the host system or other containers.

Q5: How can I remove Docker from my Ubuntu 20.04 system?

A: To remove Docker from your system, you can run the following command in the terminal:

"`
sudo apt purge docker-ce docker-ce-cli containerd.io
"`

Additionally, you can remove any remaining Docker-related files by running:

"`
sudo rm -rf /var/lib/docker
"`

Note that this will completely remove Docker from your system, including all containers and images. Make sure to backup any important data before executing these commands.