VPS guide

How to Install Docker and Docker Compose on Ubuntu

By Gander Web · Published 16 October 2026 · 3 min read

Short answer

Add Docker's apt repository, install docker-ce and the Compose plugin, and test with sudo docker run hello-world. Run apps from a compose.yaml file, publish their ports on 127.0.0.1 only, and cap log sizes in /etc/docker/daemon.json.

Install Docker from Docker's own repository rather than Ubuntu's docker.io package: you get Docker's current releases, and the Compose plugin comes from the same place. These steps follow Docker's install guide for Ubuntu 24.04, with the differences for Debian and AlmaLinux noted.

Add Docker's repository

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, change ubuntu to debian in both URLs, and use $(. /etc/os-release && echo "$VERSION_CODENAME") for the Suites line.

Install Docker

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

hello-world prints a short message and exits, which shows Docker can download and run images. On AlmaLinux and Rocky, Docker isn't started after installing, so enable it yourself:

sudo dnf install dnf-plugins-core
sudo dnf config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo
sudo dnf install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo systemctl enable --now docker

Run Docker without sudo

sudo usermod -aG docker $USER

Log out and back in for it to take effect. Anyone in the docker group can control the whole server through Docker, so only add accounts you'd trust with root.

Run an app with Docker Compose

Compose describes containers in a file, so you can recreate them with one command. As an example, this runs Uptime Kuma, a self-hosted uptime monitor:

mkdir -p ~/uptime-kuma && cd ~/uptime-kuma
nano compose.yaml
services:
  uptime-kuma:
    image: louislam/uptime-kuma:1
    restart: unless-stopped
    ports:
      - "127.0.0.1:3001:3001"
    volumes:
      - ./data:/app/data
docker compose up -d
docker compose ps
docker compose logs -f

restart: unless-stopped starts the container again after a reboot. The app's data lives in ./data next to the file, so it survives updates and is easy to include in backups.

Keep container ports off the internet

The ports line above publishes Uptime Kuma on 127.0.0.1 only. Ports Docker publishes skip UFW's rules, so writing "3001:3001" without the address would open it to the whole internet, whatever your firewall says. Put Nginx with a Let's Encrypt certificate in front instead. Uptime Kuma uses WebSockets, so its Nginx location block needs the upgrade headers as well:

location / {
    proxy_pass http://127.0.0.1:3001;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $host;
}

Update a Compose app

cd ~/uptime-kuma
docker compose pull
docker compose up -d
docker image prune

pull downloads newer images, up -d recreates any container whose image changed, and image prune deletes the old images it leaves behind.

Stop logs filling the disk

By default Docker keeps every line a container logs, with no size limit. Cap it in /etc/docker/daemon.json:

{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  }
}
sudo systemctl restart docker

The limit only applies to containers created after the restart, so recreate existing ones with docker compose up -d --force-recreate. docker system df shows how much space images, containers and volumes are using.

UK VPS hosting with full root access

Guaranteed AMD EPYC cores, SSD RAID storage and DDoS protection on every plan, from £5.99 a month with no VAT to add. Need faster cores? Upgrade to Ryzen.

See VPS plans

Questions

Should I install docker.io from Ubuntu's repository instead?

It works, but it often lags behind Docker's own releases. Docker's repository gives you current Docker Engine and the Compose plugin, and both update with apt upgrade.

Why can I reach a container even though UFW blocks the port?

Docker writes its own firewall rules, and published ports bypass UFW's. Publish ports on 127.0.0.1 and use a reverse proxy, or don't publish them at all.

How do I back up Docker apps?

Back up the folders mounted into your containers and your compose.yaml files. Images can be downloaded again. For a database in a container, back up a dump rather than its live files.

How much RAM does Docker need?

Docker itself uses very little. Size the VPS for the apps you run in it: a few small containers fit on 2 GB, while databases and Java apps need more.

Sources

  1. Install Docker Engine on Ubuntu (Docker docs)
  2. Linux post-installation steps (Docker docs)
  3. JSON File logging driver (Docker docs)

Commands are for Ubuntu 24.04, Debian 12 and AlmaLinux 9, as of 16 October 2026. If something here no longer matches what you see, tell us and we'll update it.