How to Install and Use Docker on Ubuntu 20.04

Published on February 27, 2024

With the current technology, developers can comfortably package and run applications as containers. This containerization feature makes creating and deploying applications in an isolated environment easy, and you can run different containers on a host. Docker is one of the containerization platforms that you can use for packaging and running applications in containers. Installing Docker is a straightforward task for someone using Ubuntu, and you can use two methods. Both are covered in this post.

Two Methods of Installing and Using Docker on Ubuntu 20.04

Throughout this post, we will focus on installing Docker on Ubuntu 20.04. If you use a different version, follow along and apply the same logic for your case.

Method 1: Installing Docker from the Ubuntu 20.04 Repository

Docker is available in the Ubuntu repository, and if you want a smooth and easy installation, this option is the best method. However, this option doesn’t expose you to the latest available version.

Start with updating the repository.

Copy

You can then install Docker via the apt command below.

Copy

We’ve added ‘y to avoid getting any prompts during the installation.

Once the docker.io package installs, install docker as a snap package to install all the dependency packages for a seamless installation.

For that, use the snap command below.

Copy

That’s it! Once the snap package downloads and installs, you will have Docker on your system. You can verify this by checking its version. For our case, we’ve installed Docker version 24.0.5.

Method 2: Installing Docker from Its Official Repository

The best way to get the latest Docker version is by accessing the official Docker repository during the installation. For that, you must first source and add the official repository to your local system and use it during the installation.

Begin your installation by updating your local repository.

To use the official Docker repository, we must add other prerequisite packages to our Ubuntu 22.04. While some might already be installed on your system, run the command below to install these prerequisite packages while skipping those already installed.

Copy

Curl is one of the prerequisite packages that we’ve installed. We then need to use it to access the GPG key for the official Docker repository. In the command below, we’ve sourced and added the GPG key to our system.

Copy

You will get an OK output confirming that the GPG key has been added successfully.

The next step is to add the sourced Docker repository to our APT sources on our local system. For that, run the below command.

Copy

Before we can run the install command, it’s recommended that we specify the repository to use during the installation. That way, we will ensure we source Docker from the added repository instead of the local repository. Run the command below for that.

Copy

In the above output, you notice that even though Docker is not yet installed, we are using the Docker repository for Ubuntu 20.04, and the available version is different from what we installed with the previous method.

You can now install Docker.

Copy

Confirm the installation when prompted and let the process run to completion.

We can check the installed Docker version to verify that Docker is installed and that we have a more recent version than what we got in method 1.

How to Use Docker on Ubuntu 20.04

How you use Docker will depend on what your goal is. You can use images, containers, volumes, etc. For this section, we’ve covered some basic usage examples to get you started.

First, to verify that our Docker installation is successful, let’s run the hello-world image with the command below.

Copy

You can list the available images as shown below,

Copy

You can also search for a particular image by specifying its name. Let’s try searching for the Nginx image.

Copy

After searching for an image, you can use the pull command to access it.

Copy

The pulled image will appear in our images list and is now available for local use.

The above are a few examples of how to use Docker. There are plenty of activities that you can perform with Docker, and it’s best to get a comprehensive Docker guide to get comfortable using it.

Conclusion

There are two ways of installing Docker on Ubuntu 20.04. This post has discussed each method and given the steps to follow to ensure you manage to get Docker up and running. Moreover, we’ve discussed a few examples of how to use Docker. With these insights, you can now easily install and use Docker on Ubuntu 20.04.

New to LinuxMeta? Get Started Now! 

Instantly Deploy Linux & Windows KVM VPS at a Cheap Price