Cybersecurity Updates & Tools

Install Docker on Ubuntu 20.04: Complete Step-by-Step Guide

Docker is an open-source platform that lets you package and run applications inside containers. Each container holds everything the app needs the code, runtime, and libraries so it runs the same way on any machine, from your laptop to a production server.

It is widely used in modern software development for things like:

  • Packaging apps so they run consistently in any environment
  • Running isolated services without touching the host machine
  • Speeding up CI/CD pipelines with fast, repeatable builds

This guide covers how to install Docker on Ubuntu 20.04 using the official Docker repository. The Ubuntu default repositories may carry an older version, so we use the official source to get the latest release.

Install Docker on Ubuntu from the Official Repository

Start by installing the packages needed to add a new HTTPS repository:

bashsudo apt updatesudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

These tools let apt download packages securely over HTTPS. Next, import the Docker GPG key. This confirms that the packages you install come from Docker’s official servers:

bashcurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Add the official Docker APT repository:

bashsudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

Install the latest version of Docker:

bashsudo apt updatesudo apt install docker-ce docker-ce-cli containerd.io

If you need a specific version, first list all available versions:

bashapt list -a docker-ce

Then install the one you want:

bashsudo apt install docker-ce=<VERSION> docker-ce-cli=<VERSION> containerd.io

Docker starts on its own after install. Check that it is running:

bashsudo systemctl status docker

Look for active (running) in the output.

To update Docker when a new version comes out, run sudo apt update && sudo apt upgrade. To stop Docker from updating automatically, mark the package as held:

bashsudo apt-mark hold docker-ce

Run Docker Without sudo

By default, Docker commands need root or sudo. That is not practical for regular use. To run Docker as a normal user, add your account to the docker group:

bashsudo usermod -aG docker $USER

$USER is an environment variable that holds your username. Log out and log back in for the change to take effect.

Once you are back in, you can run Docker commands without sudo. Test it quickly with:

bashdocker ps

If you see a container list (or an empty table) with no permission error, the group change worked.

Verify the Installation

Run a test container to confirm Docker is fully working:

bashdocker container run hello-world

Docker pulls the hello-world image from Docker Hub, the default public container registry, and runs it. If you see “Hello from Docker!” in the output, your install is complete.

The container exits on its own because it has no long-running process. That is expected behavior.

Remove Docker from Your System

Before uninstalling, clean up all containers, images, volumes, and networks first:

bashdocker container stop $(docker container ls -aq)docker system prune -a --volumes

Then remove the Docker packages:

bashsudo apt purge docker-cesudo apt autoremove

This removes Docker and clears out any leftover dependencies.

Docker is now installed and ready to go on your Ubuntu machine. Start by pulling a few images from Docker Hub and running some containers to get comfortable with how it works. When you are ready to manage apps that need multiple containers, Docker Compose is the next thing to explore. Got questions? Leave a comment below.