How to Install Docker on Ubuntu?

This article provides a straightforward, step-by-step guide to installing Docker on an Ubuntu system. You will learn how to update your package index, install the necessary dependencies, add Docker’s official repository, and set up the Docker Engine. By the end of this guide, you will have a fully functioning Docker installation ready to deploy containerized applications.

Step 1: Update Your System

Before installing any new software, it is best practice to update your local package index to ensure you have access to the latest software versions. Open your terminal and run the following command:

sudo apt update && sudo apt upgrade -y

Step 2: Install Required Dependencies

Docker requires a few prerequisite packages to allow the apt package manager to use repositories over HTTPS. Install these by executing:

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

Step 3: Add Docker’s Official GPG Key

The GPG key verifies the authenticity of the software packages you will download from the Docker repository. Add the key to your system with this command:

sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

Step 4: Set Up the Docker Repository

Next, add the official Docker repository to your Ubuntu apt sources. This ensures you download Docker directly from the source rather than the default Ubuntu repositories, which may feature older versions.

echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Step 5: Install Docker Engine

With the repository successfully added, update your package index once more so apt recognizes the new Docker packages, then install Docker Engine, the CLI, and containerd.

sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y

Step 6: Verify the Installation

Once the installation finishes, the Docker service should start automatically. You can verify that Docker is active and running correctly by checking its status:

sudo systemctl status docker

To complete the verification, run the standard “hello-world” container. This command downloads a test image and runs it inside a container to confirm everything works as expected:

sudo docker run hello-world