CodeBrowser

We earn commissions when you shop through the links below. Learn more

How to Install Docker on Ubuntu (26.04 and 24.04)

Install Docker Engine and Docker Compose on Ubuntu the official way, run your first container, use Docker without sudo, and avoid the firewall mistake that exposes most new Docker servers.

Ubuntu 26.04 & 24.04Official Docker repositoryDocker ComposeFirewall warning

Before you start

What you need

  • A 64-bit server running Ubuntu 26.04, 24.04 or 22.04 LTS.
  • A user with sudo access, connected over SSH.
  • At least 1 GB of RAM; 2 GB or more if you plan to run databases or several containers.

Starting from scratch? Our beginner guide on how to set up a VPS gets you a secure Ubuntu server in about 30 minutes.

Remove old versions first

If Ubuntu’s own docker.io package or another unofficial version is installed, remove it so it doesn’t conflict:

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

Steps 1–3

Install Docker from the official repository

These are the steps from Docker’s own documentation. Using Docker’s repository gets you the latest version and updates with apt upgrade.

1. Add Docker’s signing key

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

2. Add the Docker repository

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

3. Install Docker and Compose

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

Check it works with sudo docker run hello-world. Docker downloads a tiny test image and prints “Hello from Docker!”

Step 4

Run Docker without sudo

Add your user to the docker group, then log out and back in (or run newgrp docker) for it to take effect.

sudo usermod -aG docker $USER

Membership of the docker group is effectively root access on the server, so only add users you trust.

The quick way (for testing)

Docker also offers a convenience script that does steps 1–3 for you. Docker recommends it only for test and development servers:

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

Important

Docker bypasses UFW: protect your ports

This catches almost everyone. When you publish a port with -p 8080:80, Docker adds its own firewall rules that skip UFW entirely. Your container is reachable from the whole internet, even if ufw status says the port is closed.

Publish only to the server itself

docker run -d -p 127.0.0.1:8080:80 nginx

Same thing in docker-compose.yml

ports:
  - "127.0.0.1:8080:80"

Bind services to 127.0.0.1 and put a reverse proxy such as Nginx or Caddy in front of anything that should be public. Databases should never be published to the internet.

Step 5

Run your first real app with Docker Compose

Docker Compose describes your containers in one file. Create a folder, save this as compose.yaml, and start it with docker compose up -d:

compose.yaml

services:
  web:
    image: nginx:latest
    ports:
      - "127.0.0.1:8080:80"
    restart: unless-stopped

Everyday Docker commands

docker compose up -d      # start
docker compose ps         # status
docker compose logs -f    # logs
docker compose down       # stop
docker system prune       # clean up

Need a server?

Need a server for your containers?

Docker loves RAM. These hosts give you plenty for the price, and all of them run Ubuntu with full root access.

Best overall

DigitalOcean

Simple cloud servers with great docs. Add your SSH key when you create a Droplet.

From about $4/month

View DigitalOcean deals
Most RAM for the money

Hostinger

4 GB of RAM and NVMe storage on the entry VPS plan, with an easy control panel.

About $5.19/month on a 24-month term with our extra 20% off

Get 20% off Hostinger VPS
Best budget

RackNerd

Yearly KVM VPS deals for about the price of one month elsewhere. Great for learning.

From about $11/year on promo

View RackNerd deals

Prices are approximate. Compare all VPS hosts, including Vultr and ShockHosting.

FAQ

Docker on Ubuntu questions, answered

Should I install docker.io or docker-ce?

docker-ce from Docker’s own repository is the official, most up-to-date version and is what Docker documents. Ubuntu’s docker.io package works but often lags behind. Do not install both.

How much RAM does Docker need?

Docker itself uses very little. What matters is your containers: 1 GB runs a few small services, while databases, WordPress or several apps are happier with 2 to 4 GB.

Is docker-compose the same as docker compose?

docker compose, with a space, is the current version, installed as a Docker plugin. The older docker-compose command with a hyphen is deprecated, but most compose files work with both.

How do I update Docker?

Because it comes from Docker’s repository, a normal sudo apt update and sudo apt upgrade updates Docker along with the rest of the system.

Why can people reach my container when UFW blocks the port?

Docker writes its own iptables rules that take effect before UFW’s. Bind published ports to 127.0.0.1, or add rules to the DOCKER-USER chain, to keep containers private.

How do I uninstall Docker?

Run 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 if you also want to remove all images and data.

Pick the right server for your containers

Compare VPS hosts by RAM, price and one-click Docker images to find the best home for your containers.

Best VPS for Docker