beginner 10 minutes

How to Install Docker on Ubuntu

Step-by-step guide to install Docker Engine and Docker Compose on Ubuntu Linux.

Prerequisites

  • Ubuntu 20.04 or newer
  • sudo/root access
  • Internet connection
1

Update Package Index

First, update your existing list of packages:

sudo apt update
2

Install Prerequisites

Install packages needed to use a repository over HTTPS:

sudo apt install apt-transport-https ca-certificates curl gnupg lsb-release
3

Add Docker's GPG Key

Add the official Docker GPG key to verify packages:

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

Add Docker Repository

Set up the stable Docker repository:

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

Install Docker Engine

Update apt and install Docker:

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

Add User to Docker Group

Run Docker without sudo by adding your user to the docker group:

sudo usermod -aG docker $USER

You need to log out and back in for this to take effect.

7

Verify Installation

Test that Docker is working correctly:

docker run hello-world