Cloud VPS from $1.98/mo · pay with Bitcoin, Ethereum, Monero, USDT or Solana · paid in crypto
DevOps

Install Docker Engine on Ubuntu or Debian, the official way

Install Docker Engine from Docker's own apt repository on Ubuntu or Debian, then close the firewall gap, cap log growth and treat the docker group as root.

CloudSat teamNovember 18, 20267 min read
Translucent shipping containers stacked on top of a glowing server block, drawn in soft blue and violet gradients
On this pagePick the right package source

Installing Docker on a server takes five minutes. The defaults it leaves behind can cost you a weekend: ports that ignore your firewall, log files that grow until the disk is full, and a group membership that quietly hands out root. This guide installs Docker Engine from Docker's own repository on Ubuntu or Debian, then fixes those three defaults before anything goes live.

Pick the right package source

There are two common ways to get Docker on a Debian-family server, and they are not interchangeable.

Source Package names What you get
Your distribution's archive docker.io, docker-compose-v2 A version frozen with the release, patched by the distribution
Docker's apt repository docker-ce, docker-ce-cli, containerd.io, plus the Buildx and Compose plugins Current upstream releases (the 29.x line in November 2026)

The distribution package is a reasonable choice if you value a fixed version and only need basic containers. Most tutorials, Compose files and self-hosted platforms assume the upstream packages, though, and mixing the two causes conflicts. This guide uses Docker's repository.

Docker Desktop is a different product for laptops and workstations. A server only needs Docker Engine.

Check the release and clean up old packages

Docker's documentation currently lists these 64-bit releases as supported:

  • Ubuntu 26.10, 26.04 LTS, 24.04 LTS and 22.04 LTS
  • Debian 13 (trixie) and Debian 12 (bookworm)

Derivatives such as Linux Mint can work but are not officially supported. Confirm what you are running with cat /etc/os-release.

If anything Docker-related was installed earlier, from the distribution or a previous attempt, remove it first. The command below only removes packages that are actually present. Images and volumes in /var/lib/docker are not deleted by this step.

sudo apt remove $(dpkg --get-selections docker.io docker-compose docker-compose-v2 \
  docker-doc docker-buildx podman-docker containerd runc | cut -f1)

Add Docker's apt repository

The repository is signed with a key that you store in /etc/apt/keyrings, and the source is written in the newer deb822 format. On Ubuntu:

sudo apt update
sudo apt 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

sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Architectures: $(dpkg --print-architecture)
Signed-By: /etc/apt/keyrings/docker.asc
EOF

sudo apt update

On Debian, replace ubuntu with debian in both URLs and use $VERSION_CODENAME for the Suites line. Everything else is identical. The repository carries builds for amd64, arm64 and a few other architectures, and the Architectures line picks the right one for the machine, so the same block works on an ARM server.

Install the engine and plugins

sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo systemctl status docker --no-pager
sudo docker run --rm hello-world
docker compose version

The hello-world container prints a short message and exits. If it does, the daemon, the image pull and the container runtime all work. Compose is now a plugin, so the command is docker compose with a space; the old docker-compose binary is not part of this install.

If you build servers often, the whole block above can go into a startup script so every new CloudSat server boots with Docker already installed.

Three defaults to change before going live

The docker group is root

Docker's post-install notes suggest adding your user to the docker group so you can drop sudo. Understand what that grants: anyone in the group can start a container that mounts / from the host and edit any file on it. Membership is root access with extra steps.

sudo usermod -aG docker deploy   # only for accounts you would trust with sudo

If that trade is not acceptable, keep using sudo docker, or run the daemon in rootless mode with dockerd-rootless-setuptool.sh install (it needs the uidmap package). Rootless mode has limits around low ports and some networking features, so test your stack before committing to it.

Published ports skip UFW

This one surprises almost everyone. When a container publishes a port with -p 8080:80 or a ports: entry, Docker writes NAT rules that route traffic before UFW's rules are evaluated. Docker's own documentation says the packets are routed before the firewall rules can be applied. Your ufw deny 8080 does nothing.

Three fixes, from simplest to most involved:

  1. Bind ports that only a local reverse proxy needs to the loopback address: "127.0.0.1:8080:80" in Compose. Only the proxy on ports 80 and 443 faces the internet.
  2. Filter at the provider level. A cloud firewall in front of the server sees traffic before Docker does; on CloudSat that is the firewall feature in the console.
  3. Add your own rules to the DOCKER-USER iptables chain, which Docker evaluates before its own forwarding rules.

Also note that Docker supports iptables-nft and iptables-legacy, while hand-written nft rules are not supported alongside it. An nftables backend exists but is still marked experimental.

Logs grow without a limit

The default json-file logging driver does not rotate anything. A chatty container can fill the disk, and when the disk fills, databases are the first to break. Switch the default to the local driver, which rotates and compresses:

sudo tee /etc/docker/daemon.json <<'EOF'
{
  "log-driver": "local",
  "log-opts": { "max-size": "10m", "max-file": "3" },
  "live-restore": true
}
EOF
sudo systemctl restart docker

New logging settings only apply to containers created after the restart, so recreate existing ones with docker compose up -d --force-recreate. The live-restore option keeps standalone containers running while the daemon itself restarts, which makes routine engine updates less disruptive. The Compose logs guide covers reading and filtering what gets kept.

Updates and version pinning

Docker packages update through apt like everything else. Two habits help on production servers:

apt list --all-versions docker-ce     # see what the repository offers
sudo apt-mark hold docker-ce docker-ce-cli containerd.io   # freeze until you choose
sudo apt-mark unhold docker-ce docker-ce-cli containerd.io # release the hold

Holding the packages stops unattended upgrades from restarting the engine at a random hour. Read the release notes before a major version jump, then unhold, upgrade and check your containers during a window you picked.

Keep an eye on disk usage

Everything Docker stores lives under /var/lib/docker: image layers, container filesystems, volumes and build cache. On a small NVMe disk, old images from months of deploys add up quietly.

sudo docker system df                              # images, containers, volumes, cache
sudo docker image prune -a --filter "until=168h"   # unused images older than 7 days
sudo docker builder prune --filter "until=168h"    # stale build cache

Leave volumes out of automatic cleanup. docker volume prune --all deletes every named volume that no container references, and a project taken down with docker compose down leaves its database volume in exactly that state.

A first Compose project

With the engine in place, a minimal project shows the loopback binding from earlier. Save it as /srv/whoami/compose.yaml:

services:
  whoami:
    image: traefik/whoami:latest
    ports:
      - "127.0.0.1:8080:80"
    restart: unless-stopped
cd /srv/whoami && sudo docker compose up -d
curl -s http://127.0.0.1:8080 | head -n 3

Bound to 127.0.0.1, the container responds on the server itself and cannot be reached from the internet until a reverse proxy sits in front of it. From here, a web UI such as Arcane or a self-hosted PaaS can manage the same engine.

FAQ

Should I use docker.io or docker-ce?

Use docker-ce from Docker's repository when you follow upstream documentation or run tools that expect recent Compose features. Use docker.io if you prefer the distribution's frozen, security-patched version. Do not install both.

Does a server need Docker Desktop?

No. Docker Desktop bundles a virtual machine and a GUI for workstations. On a Linux server, Docker Engine is the whole product.

How do I remove Docker completely?

Purge the packages with sudo apt purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin, then delete /var/lib/docker and /var/lib/containerd. That last step erases every image, container and volume, so back up volumes first.

Can I use Podman instead?

Yes. Podman runs most images and many Compose files through podman compose, and it runs rootless by default. Some tools that talk to the Docker socket directly need extra setup, so check their documentation first.

Run it on CloudSat. Cloud VPS on AMD EPYC and NVMe from $1.98/mo in 13 regions, delivered in under 5 minutes and paid in crypto. See plans or deploy a server.