Host Your Own AI Agent with OpenClaw - Free 1-Click Setup!

How to Install Docker on Ubuntu: Step-by-Step Guide 

What you need to know:

How to Install Docker on Ubuntu: Step-by-Step Guide 
  • Installing Docker on Ubuntu takes four steps: update packages, add the Docker repository, install Docker Engine, and verify the install.
  • The official Docker apt repository is the recommended source, not the Snap package.
  • Docker Compose now ships as a plugin (docker compose, v2), not the older docker-compose binary.
  • Add your user to the docker group to avoid typing sudo for every command.
  • On a Contabo VPS, you can either install Docker manually or preselect the Docker Add-On at checkout so the server comes ready to use.

Docker on Ubuntu is one of the most common setups for self-hosting, development, and running small production services. This guide walks through a clean install on Ubuntu 26.04 LTS and 24.04 LTS, covers Docker Compose, and handles the errors people usually hit the first time. If you are on a fresh Ubuntu VPS, you can follow the steps top to bottom and have Docker working in under ten minutes.

What Is Docker and Why Install It on Ubuntu

So what is Docker? Docker is a platform for running applications inside containers. A container is a lightweight, isolated environment that holds an app and the files it needs to run, all packaged together. You build an image once, then run it anywhere Docker works.

Running Docker on Ubuntu makes sense because Ubuntu is the most common Linux distribution for servers, and Docker’s own repositories officially support it. Ubuntu LTS releases stay supported for years. If you run a Contabo VPS with Ubuntu, Docker is usually the fastest way to deploy a database, a web app, a reverse proxy, or a full stack with Docker Compose.

Docker Containers vs Virtual Machines

Docker containers and virtual machines both isolate workloads, but they work differently. A virtual machine boots an entire guest operating system on top of a hypervisor. Docker containers share the host kernel and only package the application and its dependencies, which makes them faster to start and lighter on resources.

In practice, Docker Engine is a much thinner layer than a full VM hypervisor. A VM might take 30 seconds to boot and use a gigabyte of RAM doing nothing. A Docker container often starts in under a second and only uses the memory its process actually needs. VMs still have a place for strong isolation or running different kernels, but for most Linux workloads, Docker Engine is the simpler choice.

Prerequisites for Installing Docker on Ubuntu

Before you install Docker Ubuntu-side, make sure a few basics are in place. You need a user account with sudo privileges, internet access to reach the Docker repository, and a supported Ubuntu release. Install Docker Ubuntu guides tend to skip these parts, but they are where most first-time issues start.

It also helps to update the system first and remove any older Docker packages that might be on it. Snap-installed Docker, in particular, can conflict with the official apt install.

sudo apt update && sudo apt upgrade -y
sudo apt remove docker docker-engine docker.io containerd runc
sudo snap remove docker 2>/dev/null || true

If the server is brand new, the removal commands are safe to skip.

Supported Ubuntu Versions and System Requirements

The install Docker Ubuntu process officially supports the current LTS releases, which at the time of writing are Ubuntu 26.04 LTS (Resolute Raccoon) and Ubuntu 24.04 LTS, plus the latest interim release, Ubuntu 25.10. Docker Engine runs on x86_64 and arm64, with a 64-bit kernel required.

System requirements depend more on what you run in Docker than on Docker itself. Docker Engine on its own is light. The real RAM and CPU cost comes from the applications inside your containers. A Postgres database, a Node API, and a reverse proxy together will need very different headroom than a single static site.

As a rough baseline, a small VPS with 1 GB of RAM is enough for Docker Engine plus a light workload such as one or two small containers. 2 GB is more comfortable once you stack a database, an app, and a reverse proxy. For anything closer to production, size the host around your application’s real memory profile and treat Docker’s own overhead as a small constant on top. Plan for at least a few gigabytes of free disk space, and keep an eye on /var/lib/docker, where all images and volumes live by default. If your server sits behind a strict firewall, make sure outbound HTTPS is open to download.docker.com.

How to Install Docker on Ubuntu Manually

This is the install Docker Ubuntu sequence in full, done by hand. The steps below cover Ubuntu 26.04 LTS, 25.10, and 24.04 LTS identically. Run the commands as a user with sudo access. Docker Ubuntu installs become predictable once you follow these four steps in order.

Step 1: Update Packages and Install Dependencies

Start with a package index refresh and a few helpers the install Docker Ubuntu steps will need. These are standard Docker commands most Linux users already know.

sudo apt update
sudo apt install -y ca-certificates curl gnupg lsb-release

That gets your system ready to talk to the Docker repository over HTTPS and to verify the signing key.

Step 2: Add Docker GPG Key and Repository

Next, add the Docker GPG key to your system’s keyring, then add the Docker repository to apt. The Docker GPG key is how your system verifies that the packages you download are genuinely from Docker.

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 update

The $(. /etc/os-release && echo "$VERSION_CODENAME") part picks the right Docker repository for your release, whether noble (24.04), questing (25.10), or resolute (26.04). If apt complains about a missing key, the Docker GPG key step did not land. Re-run it.

Step 3: Install Docker Engine

Now install Docker Engine and the related packages. This is the install Docker Engine step most guides call “the real one.” Everything before it was setup.

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

That single command installs Docker Engine, the CLI, the container runtime, the Buildx plugin, and the Compose plugin. Docker Engine will be running as a systemd service right after install. You can confirm with sudo systemctl is-active docker.

Step 4: Verify Docker Installation

The last step is to verify Docker installation worked. The cleanest check is running the hello-world image.

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

You should see the Docker Engine version and an active (running) service status. If both look healthy, the install worked.

Installing Docker on a Contabo VPS

If your Ubuntu server is a Contabo VPS, you have two paths. The first is the manual install above, which works on any Contabo VPS image running a supported Ubuntu release. The second simpler method is to choose the Docker Add-On at checkout, which provisions the VPS with Docker already installed and configured. Both paths produce the same working Docker Engine in the end, just with different effort and timing.

Option A: Use the Contabo Docker Add-On at Checkout

When you order a Contabo VPS, the configurator offers Add-Ons alongside the base OS choice. Simply select it during checkout. The VPS is then delivered with Docker Engine and the Docker Compose plugin already installed, the service enabled on boot, and a working docker command out of the box.

This is the fastest way to go from order to working container host. After the server is provisioned, SSH in and check the install:

docker --version
docker compose version
sudo systemctl status docker

If all three look healthy, you can skip straight to the configuration and Docker Compose sections below. You will still want to add your user to the docker group and apply the configuration tips, because the Add-On installs Docker but leaves day-to-day preferences up to you.

Option B: Manual Install on an Existing Contabo VPS

If your Contabo VPS is already running and you did not pick the Add-On at checkout, you can either reinstall the server including Docker via your Customer Control Panel (note that this will wipe all data on the server, so be careful with this method) or you can install Docker manually using the four-step process above. Nothing about a Contabo VPS changes the commands. The apt repository, Docker GPG key, and Docker Engine packages are exactly the same.

A few Contabo-specific notes worth keeping in mind on a fresh VPS:

  • Confirm your VPS image is a supported Ubuntu LTS release (24.04 or 26.04).
  • Run sudo apt update && sudo apt upgrade -y before installing Docker to pull in pending security updates.
  • If you use the Contabo firewall or Cloud-Init, check that outbound HTTPS is open so apt can reach download.docker.com.
  • After install, set up SSH key-only login and a non-root user before you start running services under Docker.

Those steps are standard Linux server hygiene, and they matter more once you are running real workloads in containers.

Installing Docker Compose on Ubuntu

Docker Compose lets you define a multi-container stack in one YAML file and run it with a single command. Since you installed the docker-compose-plugin package in Step 3 (or got it via the Contabo Add-On), Docker Compose is already available as docker compose (with a space).

docker compose version

A simple docker-compose.yml file looks like this:

services:
web:
image: nginx:alpine
ports:
- "8080:80"
db:
image: postgres:16
environment:
POSTGRES_PASSWORD: changeme

Save that in a folder, then run docker compose up -d inside it. Docker Compose will pull the images, create the containers, and start them in the background. Stop the stack with docker compose down. For anything beyond a toy setup, move secrets into a .env file and commit only the template.

Docker Compose v2 vs v1 Plugin

Docker Compose v2 is the current version and ships as a Docker CLI plugin. You call it with docker compose. The older v1 was a separate Python tool called with docker-compose (hyphen). It is no longer actively maintained, and new installs should use v2. The Compose file format is identical across versions, so most old tutorials still work if you just change the invocation.

Essential Docker Configuration Tips

Once Docker runs, a few small Docker configuration tips save a lot of friction. These are quick Docker commands and Docker setup tweaks that make daily use smoother.

  • Add your user to the docker group so you do not need sudo for every command.
  • Enable the Docker daemon on boot so containers come back after a reboot.
  • Set log rotation so container logs do not fill your disk.
  • Use named volumes for data you want to keep between container recreations.
  • Pin image tags rather than using latest, which can shift unexpectedly.

For log rotation, set sensible defaults in /etc/docker/daemon.json, then restart Docker with sudo systemctl restart docker:

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

Managing Docker with Non-Root Users

Docker management on Ubuntu is easier when your normal user can run Docker commands without sudo. Add the user to the docker group, then log out and back in so the group membership takes effect.

sudo usermod -aG docker $USER
newgrp docker
docker ps

The final docker ps confirms Docker management is working without elevated privileges. Members of the docker group effectively have root on the host, so treat that group membership as privileged access.

Configuring Docker to Start on Boot

To configure Docker to start automatically after a reboot, enable the service with systemd.

sudo systemctl enable docker
sudo systemctl enable containerd

If you also want containers that were running to come back up, add a restart policy to each container or each service in your Compose file:

restart: unless-stopped

unless-stopped restarts the container after a reboot or a crash, but leaves it alone if you stop it on purpose. That is usually the right default for production.

Troubleshooting Common Docker Issues

Docker troubleshooting on Ubuntu usually comes down to three things: the daemon is not running, your user is not in the docker group, or a package step failed silently. If any command fails, check the daemon first.

sudo systemctl status docker
sudo journalctl -u docker -e

The journal usually tells you exactly what is wrong, whether it is a port conflict, a broken config file, or a missing dependency. Docker troubleshooting is much faster when you read the logs before guessing.

Permission Denied and Daemon Errors

Permission denied and daemon errors are the most common Docker issues for new installs. You will see one of these two patterns:

  • permission denied while trying to connect to the Docker daemon socket means your user is not in the docker group. Add it with sudo usermod -aG docker $USER, then log out and back in.
  • Cannot connect to the Docker daemon usually means the service is not running. Start it with sudo systemctl start docker and enable it on boot with sudo systemctl enable docker.

If the daemon still refuses to start, check the journal output above. Most Docker issues at this stage come from a bad /etc/docker/daemon.json file or a conflicting older install that was not fully removed. If docker pull hangs, check DNS and outbound 443 rules on the host.

FAQ: Installing Docker on Ubuntu

How do I install Docker Engine on Ubuntu 26.04 LTS?

Follow the install Docker Ubuntu steps in this guide. On Ubuntu 26.04 LTS, the process is identical to 24.04 LTS and 25.10: add the Docker GPG key and repository, then install Docker Engine with sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin. On a Contabo VPS, you can also pick the Docker Add-On at checkout and skip the manual install.

How do I install Docker Compose on Ubuntu?

Docker Compose v2 ships as a Docker CLI plugin. Install the docker-compose-plugin apt package, then run docker compose version to confirm. If you already followed Step 3 above, Docker Compose is already installed.

What Docker commands should I know first?

The most useful early Docker commands are docker run, docker ps, docker images, docker logs, and docker exec. They cover starting containers, listing what is running, checking images, reading logs, and jumping into a running container. From there, docker compose up and docker compose down handle multi-container stacks.

How do I fix Docker permission denied on Ubuntu?

The fix for permission denied errors on Docker Ubuntu installs is to add your user to the docker group with sudo usermod -aG docker $USER, then log out and back in. After that, Docker commands work without sudo. If you still see the error, confirm the Docker daemon is running with sudo systemctl status docker.

How do I set up Docker networking on Ubuntu?

Docker creates a default bridge network at install time, so basic container-to-container traffic and outbound internet work without any extra setup. For multi-container apps, create a user-defined bridge so containers can reach each other by service name: docker network create app-net, then start containers with --network app-net. With Docker Compose, every stack gets its own network automatically, and services find each other using the service name as the hostname. For containers that need to be reachable from outside, publish ports with -p host:container or the ports: key in Compose.

Scroll to Top