[!TIP]
Skip this guide and install Docker automatically:

sudo apt install curl -y && curl -fsSL https://scripts.5echo.io/ubuntu/install/docker.sh | sudo bash

Introduction

In this guide you'll learn how to install the official docker application on your Ubuntu server.

1) Uninstall old versions

Before you can install Docker Engine, you need to uninstall any conflicting packages.

Your Linux distribution may provide unofficial Docker packages, which may conflict with the official packages provided by Docker. You must uninstall these packages before you install the official version of Docker Engine.

1) The unofficial packages to uninstall are:

  • docker.io
  • docker-compose
  • docker-compose-v2
  • docker-doc
  • podman-docker
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done

2) Install using the apt repository

Set up Docker's apt repository.

# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

3) Install the Docker packages

To install the latest version, run:

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

4) Run and confirm

To confirm the installation, use this command:

sudo service docker start
sudo docker run hello-world

[!SUCCESS]

Installation completed!
Docker is now fully installed and running on your system.