Talk to the NOC, IST hours — +91 75994 50220 support@bigdomainhost.com
Guide

Install Docker Engine and Docker Compose on Ubuntu, step by step

Docker's own apt repository is the cleanest way to put Docker on an Ubuntu server. This guide follows Docker's documentation command by command, then covers the parts most tutorials skip: the docker group's root access, ports that slip past ufw, and logs that fill the disk.

Short answer: To install Docker on Ubuntu, remove old packages such as docker.io, add Docker's GPG key and apt repository, then run sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin. Test with sudo docker run hello-world. Use docker compose (with a space), remember that the docker group equals root access, and bind published ports to 127.0.0.1 because Docker ports bypass ufw.

How to install Docker on Ubuntu: the short version

To install Docker on Ubuntu, remove any old or unofficial Docker packages, add Docker's own apt repository and signing key, then install docker-ce, docker-ce-cli, containerd.io, docker-buildx-plugin and docker-compose-plugin with apt. Check it with sudo docker run hello-world. The whole job takes a few minutes on a fresh VPS, and the install commands in Steps 1 to 4 follow Docker's documentation as it stood on 23 November 2026.

On that date Docker's Ubuntu page listed four supported 64-bit releases: Ubuntu 26.10, 26.04 LTS, 24.04 LTS and 22.04 LTS. The newest Docker Engine release was 29.10.0, published on 16 November 2026, and the latest Docker Compose release was v5.8.0. Run lsb_release -a first if you are not sure which release you have; our guide on how to check your Ubuntu version covers the other ways.

Before you start: KVM vs container-based VPS

Docker containers share the kernel of the machine they run on. Docker Engine uses kernel features such as namespaces, cgroups and iptables to isolate containers and route their traffic. That works on a dedicated server or a full virtual machine, because each one runs its own kernel.

It often does not work on a container-based VPS. OpenVZ and LXC plans share the host's kernel between every customer, so you cannot load kernel modules or change kernel settings, and Docker either fails to start or runs with missing networking features. A KVM VPS is a full virtual machine with its own kernel, so Docker installs on it the same way it does on a physical server. If you are unsure what your provider sells, our explainer on what a VPS is has a section on KVM vs OpenVZ and LXC.

Also do the basic hardening first: a sudo user, SSH keys, ufw and automatic security updates. Our Ubuntu VPS initial setup guide walks through each step. The commands below assume you are logged in as that sudo user.

Quick checklist

  • 64-bit Ubuntu 22.04, 24.04, 26.04 or 26.10 on a KVM VPS or a dedicated server.
  • A sudo user, not a root login.
  • ufw already allowing SSH (you will see below why ufw does not cover Docker ports).
  • Enough disk for images: they add up faster than most people expect.

docker.io vs docker-ce: which package to install

Ubuntu's own archive has a package called docker.io. It is built and maintained by Ubuntu, not by Docker, and its version follows Ubuntu's release cycle. docker-ce (Community Edition) comes from Docker's own apt repository at download.docker.com and gets each new Docker Engine release as Docker publishes it.

docker.iodocker-ce
Built byUbuntuDocker
RepositoryUbuntu archive (no setup)Docker's apt repository (added once)
UpdatesFollow Ubuntu's packagingEach upstream Docker Engine release
ComposeSeparate Ubuntu packagesdocker-compose-plugin from Docker
Docker's install docsListed as a conflicting package to removeThe documented method

This guide uses docker-ce, because it matches Docker's documentation and you get fixes as soon as they ship. Do not install both: they conflict.

Step 1: remove old or conflicting packages

Docker's docs list the unofficial packages to remove first: docker.io, docker-compose, docker-compose-v2, docker-doc, docker-buildx and podman-docker. Docker Engine also ships its own bundle of containerd and runc as containerd.io, so separately installed containerd or runc packages have to go too. This one command removes whichever of them are installed:

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

On a fresh VPS, apt will usually report that none of them are installed. That is fine. Removing packages does not delete images, containers or volumes stored in /var/lib/docker/, so data from an earlier install stays where it is.

Step 2: add Docker's apt repository and GPG key

Download Docker's signing key into /etc/apt/keyrings, then add the repository as a deb822 .sources file. The Suites line reads your Ubuntu codename from /etc/os-release, so the same block works on every supported release.

# Add Docker's official GPG key:
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

# Add the repository to Apt sources:
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

If the last apt update shows a line for download.docker.com without errors, the repository is set up. A NO_PUBKEY error means the key file did not download, so run the curl line again and check the server can reach the internet.

Step 3: install Docker Engine, the CLI, containerd, Buildx and Compose

Install the five packages in one go:

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

On Ubuntu the Docker service starts automatically and is enabled at boot. Check it, then run the test image:

sudo systemctl status docker
sudo docker run hello-world
docker --version
docker compose version

hello-world downloads a tiny image, prints a confirmation message and exits. If the service is not running, start it with sudo systemctl start docker.

Installing a specific version

To pin a version, for example to match another server, list what the repository offers and install that exact string for both docker-ce and docker-ce-cli:

apt list --all-versions docker-ce
VERSION_STRING=5:29.10.0-1~ubuntu.24.04~noble
sudo apt install docker-ce=$VERSION_STRING docker-ce-cli=$VERSION_STRING containerd.io docker-buildx-plugin docker-compose-plugin

The string above is the Ubuntu 24.04 build of 29.10.0. Copy the exact one that apt list prints on your server. To upgrade later, run sudo apt update and sudo apt install the packages again; normal apt upgrade runs pick them up too.

Use docker compose, not docker-compose

The docker-compose-plugin package adds Compose as a subcommand, so you type docker compose up -d with a space. The old hyphenated docker-compose was Compose v1, written in Python, and it is no longer supported. Docker's docs name Compose v2 and Compose v5 as the supported versions today; v5 works the same way as v2 and adds an official Go SDK. Old tutorials that start a compose.yaml with a version: line still work, because current Compose ignores that element.

Docker also offers a convenience script at get.docker.com. Its own docs say it is not recommended for production, because it installs the latest release without asking and can bring unexpected major upgrades. On a server, use the repository method above.

Step 4: run Docker without sudo (and what that costs)

By default the Docker daemon runs as root and listens on a Unix socket, /var/run/docker.sock. Only root and members of the docker group can use that socket. That is why a plain docker ps from your own user fails with:

permission denied while trying to connect to the docker API at unix:///var/run/docker.sock

Docker 28 and earlier worded it as "permission denied while trying to connect to the Docker daemon socket at", so you will still find that phrase in older answers.

To use Docker without typing sudo each time, add your user to the group:

sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker
docker run hello-world

On Ubuntu the package normally creates the group already, so groupadd may report that it exists. Log out and back in so every new session picks up the membership; newgrp only applies it to the current shell.

The trade-off: Docker's documentation warns that the docker group grants root-level privileges. Anyone in it can start a container that mounts the host's root filesystem and change any file on the server. Treat group membership exactly like sudo access without a password. Add only the people who already have sudo, never a web application user, and never mount docker.sock into a container unless you trust that container with root. If you need real separation, Docker supports rootless mode, where the daemon runs as an ordinary user.

If you see permission denied on ~/.docker/config.json after joining the group, you ran Docker with sudo earlier and the folder is owned by root. Fix it with:

sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
sudo chmod g+rwx "$HOME/.docker" -R

Step 5: Docker and ufw (published ports bypass your firewall)

This catches many people on a new VPS. Docker's docs state it plainly: when you publish a container port, that traffic is diverted in the nat table before it reaches the INPUT and OUTPUT chains that ufw uses. So docker run -p 8080:80 nginx makes port 8080 reachable from the whole internet, even if ufw status says 8080 is denied.

Three ways to keep control:

  1. Bind to localhost. If a reverse proxy such as Nginx or Caddy on the same server is the only thing that should reach the container, publish the port on 127.0.0.1 only:
    docker run -d -p 127.0.0.1:8080:80 nginx
    In a compose.yaml file, write the same thing in the ports list:
    services:
      web:
        image: nginx
        ports:
          - "127.0.0.1:8080:80"
  2. Do not publish at all. Containers on the same user-defined network reach each other by service name. A database container that only your app uses needs no ports entry.
  3. Filter in the DOCKER-USER chain. Docker processes rules in this chain before its own. To allow only one source address to reach published ports, replace eth0 with your external interface and 203.0.113.10 with the allowed IP:
    sudo iptables -I DOCKER-USER -i eth0 ! -s 203.0.113.10 -j DROP
    sudo iptables -I DOCKER-USER -m state --state RELATED,ESTABLISHED -j ACCEPT
    Run the second command after the first. Because -I inserts at the top of the chain, the ACCEPT rule ends up above the DROP rule, so replies to connections your containers open themselves (image pulls, apt, API calls) still get through. These are IPv4 rules only. If your VPS has IPv6 and containers publish on [::], add the same pair with ip6tables, replacing 2001:db8::10 with your allowed IPv6 address:
    sudo ip6tables -I DOCKER-USER -i eth0 ! -s 2001:db8::10 -j DROP
    sudo ip6tables -I DOCKER-USER -m state --state RELATED,ESTABLISHED -j ACCEPT
    Rules added this way are not saved across reboots unless you persist them, so most single-server setups are better served by option 1, which covers IPv4 and IPv6 alike.

Do not try to fix this by setting "iptables": false in the daemon configuration. Docker's docs say that is not appropriate for most users and is likely to break container networking. Docker also supports only iptables-nft and iptables-legacy for its rules; rulesets you write directly with nft are not supported on a host running Docker. Docker 29 adds an experimental nftables backend (set "firewall-backend": "nftables" in daemon.json), but the iptables backend remains the default and the documented choice.

After starting your containers, run sudo ss -tlnp and check which addresses each port listens on. Anything on 0.0.0.0 or [::] is public.

Step 6: logs, disk use and clean-up

By default Docker uses the json-file logging driver and does not rotate its logs. A chatty container can fill a small NVMe disk on its own. Set rotation for all new containers in /etc/docker/daemon.json:

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

Then restart the daemon with sudo systemctl restart docker. The values must be strings in quotes. The setting applies only to containers created after the change, so re-create existing ones (docker compose up -d --force-recreate). Docker's docs also suggest the local logging driver, set with "log-driver": "local", which rotates by default and uses a more compact format.

To see where disk space goes and reclaim it:

docker system df
docker system prune
docker system prune -a

docker system prune removes stopped containers, unused networks, dangling images and unused build cache, and asks before it does. Adding -a also removes every image not used by a container, so the next deploy has to pull them again. Volumes are kept unless you add --volumes, and even then only anonymous volumes are removed. Check what a volume holds before you delete it: a database volume is your data.

Common errors after installing Docker

ErrorLikely causeFix
permission denied ... /var/run/docker.sockYour user is not in the docker group yetUse sudo, or add the user and log in again (Step 4)
failed to connect to the docker API at unix:///var/run/docker.sock (older versions: Cannot connect to the Docker daemon)The service is stoppedsudo systemctl start docker, then read journalctl -u docker
docker-compose: command not foundYou typed the v1 commandUse docker compose with a space
Conflicts during apt installdocker.io or containerd still installedRun the removal command in Step 1
Port open despite ufwPublished ports skip ufwBind to 127.0.0.1 or use DOCKER-USER (Step 5)

With Docker running you can move on to real projects, such as deploying a Python app on a VPS, deploying a Node.js app or self-hosting n8n with Docker Compose.

Docker on a Bigdomainhost VPS

The entry KVM VPS plan has 2 vCPU, 4 GB RAM, 40 GB NVMe and 5 TB of transfer, which is enough for a reverse proxy and a few small containers; the current price is on the pricing page. Take a snapshot before a major Docker upgrade so you can roll back in minutes if a container breaks. Billing is prepaid in 30-day periods, with no free trial. Support is on WhatsApp at +91 75994 50220 at any time, and by phone in IST working hours.

Written by the Bigdomainhost team with AI assistance; facts checked against the linked sources.

Sources (checked )

Answers

Frequently asked questions

Still unsure? Call +91 75994 50220 or write to support@bigdomainhost.com — a human replies in IST hours.

How do I install Docker on Ubuntu 24.04?

Remove any old Docker packages, add Docker's GPG key and apt repository, then run sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin. Test the install with sudo docker run hello-world. The same commands work on Ubuntu 22.04, 26.04 and 26.10.

What is the difference between docker.io and docker-ce?

docker.io is Ubuntu's own build of Docker from the Ubuntu archive, and its version follows Ubuntu's packaging. docker-ce comes from Docker's apt repository and gets every Docker Engine release as it is published. Docker's install guide treats docker.io as a conflicting package and uses docker-ce.

How do I fix permission denied on /var/run/docker.sock?

Your user cannot access the Docker socket. Either run the command with sudo, or add the user to the docker group with sudo usermod -aG docker $USER and log out and back in. Be aware that docker group membership gives root-level access to the server.

How do I install Docker Compose on Ubuntu?

Install the docker-compose-plugin package from Docker's repository, which the standard install command already includes. Then use docker compose with a space, for example docker compose up -d. The old docker-compose v1 command is no longer supported.

Why can I reach a Docker port even though ufw blocks it?

Docker writes its own iptables rules for published ports, and that traffic is redirected before it reaches the chains ufw uses. Publish ports on 127.0.0.1 when only a local reverse proxy needs them, or add rules to the DOCKER-USER chain. Do not disable Docker's iptables handling; Docker's docs say that is not appropriate for most users and is likely to break container networking.

Can I run Docker on any VPS?

Docker needs a VPS with its own kernel, which a KVM VPS has. Container-based plans such as OpenVZ or LXC share the host kernel, so Docker often fails to start or misses networking features there. Check the virtualisation type before you buy.

Support that picks up the phone.

In IST hours, in Hindi or English, and WhatsApp replies fastest at any time. Sales, migration and emergencies all reach the same engineers. No offshore queue, no 48-hour first reply.

Need cPanel or WHM with the ports already sorted?

Web & cPanel hosting comes with cPanel ready to log in to, reseller hosting adds white-label WHM, and a KVM VPS can have cPanel & WHM pre-installed. Call +91 75994 50220 or email support@bigdomainhost.com.