Install Docker on Ubuntu

This guide will help you install Docker Engine on Ubuntu (20.04/22.04+) and configure your user to run Docker commands without sudo.

1. Update Package Index

sudo apt update

2. Install Prerequisites

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

3. Add Docker’s Official GPG Key

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

4. Set Up the Stable 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

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

6. Start and Enable Docker Service

sudo systemctl enable --now docker

7. Add Your User to the Docker Group

sudo usermod -aG docker $USER
This allows you to run Docker commands without sudo.

8. Apply New Group Membership

Log out and log back in, or run:

newgrp docker

9. Verify Installation

docker run --rm hello-world

You should see:

Hello from Docker!