Skip to content
Runbook

Install Docker on Ubuntu / Debian

Container engine to package, distribute, and run applications in isolation.

Containerscontainercontainerdevopscomposeoci

Installation

Official script (quick) · Script
curl -fsSL https://get.docker.com | sh

Handy for a dev machine or a VPS. Avoid it in production: prefer the versioned APT repository below.

Official APT repository (recommended) · apt
sudo apt-get update
sudo apt-get install -y 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
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo \"$VERSION_CODENAME\") stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

For Debian, replace the ubuntu URL with debian in the GPG key and the repository.

Verify the installation

Verify
docker --version
sudo docker run --rm hello-world

Service

Start
sudo systemctl start docker
Stop
sudo systemctl stop docker
Status
sudo systemctl status docker
Restart
sudo systemctl restart docker
On boot
sudo systemctl enable --now docker

Important files

TypePathDescription
config/etc/docker/daemon.jsonDaemon configuration (registries, log driver, address range). Create it if absent.
data/var/lib/dockerImages, containers, volumes, and filesystem layers.
socket/var/run/docker.sockUnix socket through which the client talks to the daemon.

Command-line tools

  • dockerCommand-line client to manage images and containers.
  • docker composeMulti-container orchestration (docker-compose-plugin plugin).

Uninstall

Uninstall the packages
sudo apt-get purge -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Remove data and config
sudo rm -rf /var/lib/docker /var/lib/containerd /etc/docker

Destructive: erases all images, containers, and volumes.

Good to know

  • Add your user to the docker group to avoid sudo: sudo usermod -aG docker $USER (then log back in). This is equivalent to root access.
  • First uninstall the old distribution packages: sudo apt-get remove docker docker.io docker-doc docker-compose podman-docker containerd runc.

Installation on Ubuntu / Debian

Two paths coexist. The official script get.docker.com detects the distribution, adds the repository, and installs the engine in one command: ideal for a development machine or a disposable server, but discouraged in production because it always installs the latest version without any pinning control. The recommended path is Docker's official APT repository: you control the version, updates go through apt, and you get the full engine (docker-ce), the client, containerd, Buildx, and the Compose plugin.

Before any installation, remove the docker.io or docker-compose packages provided by Ubuntu: they are old and conflict with the official repository.

Service and permissions

The engine runs as the docker systemd service. Enable automatic startup with sudo systemctl enable --now docker. By default, the socket belongs to the docker group: without membership in this group, every command requires sudo. Adding yourself to the group (sudo usermod -aG docker $USER) removes this constraint but grants control equivalent to root over the machine, because the daemon runs as root.

Daemon configuration

The /etc/docker/daemon.json file (create it if it does not exist) centralizes the daemon configuration: logging driver, mirror registries, DNS, address range of the default networks. After changes, reload with sudo systemctl restart docker. The data (images, volumes, containers) resides in /var/lib/docker; this directory can grow quickly, so monitor disk space and prune regularly with docker system prune.