Skip to content

How to Install Docker and Docker Compose on Ubuntu 24.04 LTS

Running applications inside containers is the cleanest way to deploy modern software on a Linux server without dependency conflicts. Learning how to install Docker on Ubuntu 24.04 LTS lets you spin up isolated environments for web apps, databases, automation tools like n8n, and monitoring dashboards in seconds.

Instead of installing Ubuntu’s outdated default package, setting up Docker’s official repository gives you the latest stable Docker Engine alongside the modern Docker Compose v2 plugin (docker compose) in one streamlined workflow.

This step-by-step tutorial covers how to install Docker on Ubuntu 24.04 LTS on a virtual private server—including adding the official GPG key, running Docker without sudo, deploying a quick Compose test stack, and configuring essential production safeguards.

How to install Docker on Ubuntu 24.04 LTS VPS architecture showing Docker Engine, Compose v2, and isolated containers
Knowing how to install Docker on Ubuntu lets you run isolated applications and multi-container stacks cleanly on one VPS.

Prerequisites Before You Learn How to Install Docker on Ubuntu

Review these baseline server requirements before following the commands on how to install Docker on Ubuntu 24.04 LTS:

Requirement Minimum Spec Recommended Production Spec
Operating System Ubuntu 24.04 LTS (Noble Numbat) 64-bit Ubuntu 24.04 LTS (x86_64 or ARM64)
RAM (Memory) 1 GB RAM 2 GB to 4 GB+ RAM (Ideal for multi-container stacks)
Storage Space 15 GB free disk space 30 GB to 50 GB+ NVMe SSD (for images & volumes)
User Access Non-root user with sudo privileges Non-root sudo user with SSH key authentication

Tip: If you are deploying containers on a 1 GB or 2 GB VPS, add a 2 GB swap file before pulling large Docker images so memory spikes do not trigger Out-Of-Memory kills—follow our quick guide on how to add swap space Linux first.

How to Install Docker on Ubuntu 24.04 LTS Step-by-Step

Connect to your VPS via SSH as your non-root sudo user and complete these five steps for how to install Docker on Ubuntu properly.

Step 1: Remove Unofficial or Conflicting Packages

Before beginning how to install Docker on Ubuntu from the official source, remove any older or third-party container packages (such as docker.io or podman-docker) that might conflict with Docker Engine:

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

If apt reports that none of these packages are installed, that is completely normal on a fresh VPS—proceed directly to Step 2.

Step 2: Add Docker’s Official GPG Key and APT Repository

Adding Docker’s official repository is a core part of how to install Docker on Ubuntu because it ensures you receive timely security patches and the latest Compose plugin releases directly from Docker’s official Ubuntu installation repository.

First, update your package index and install prerequisite utilities:

sudo apt update
sudo apt install -y ca-certificates curl

Next, create the keyrings directory and download Docker’s official GPG signing key:

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

Now register the Docker repository in your APT sources list and refresh the package cache:

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

Step 3: Install Docker Engine and the Docker Compose Plugin

With the repository configured, install Docker Engine, the CLI, containerd, Buildx, and the Docker Compose v2 plugin in one command—completing the main installation phase of how to install Docker on Ubuntu:

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

Confirm that both Docker Engine and Docker Compose v2 are installed and active:

docker --version
docker compose version
sudo systemctl status docker --no-pager

You should see active (running) in the systemd output along with the installed Docker and Compose version numbers.

Step 4: Configure Docker to Run Without sudo

By default, the Docker daemon binds to a Unix socket owned by root, meaning every command requires typing sudo. To run commands cleanly as your regular user after completing how to install Docker on Ubuntu, add your account to the docker group:

sudo usermod -aG docker $USER

Apply the new group membership immediately without logging out and back in:

newgrp docker

Security Note: Because members of the docker group effectively have root-level host privileges through volume mounts, only add trusted administrative users to this group. For full server access protection, review our Linux server hardening checklist.

Step 5: Verify Your Setup with a Test Container

Run Docker’s lightweight hello-world image to verify that your user permissions, image pulls, and container runtime work properly:

docker run hello-world

When Docker prints Hello from Docker! This message shows that your installation appears to be working correctly., you have successfully finished how to install Docker on Ubuntu. Clean up the test container and image afterward:

docker container prune -f
docker image rm hello-world
How to install Docker on Ubuntu terminal verification showing docker compose version and hello-world test
Verifying Docker Engine, Docker Compose v2, and non-root execution confirms your Ubuntu 24.04 VPS is ready for containers.

Quick Test: Launch a Container with Docker Compose

Once you complete how to install Docker on Ubuntu, you will manage almost all real-world applications using compose.yml files rather than long docker run commands. Test Docker Compose v2 by spinning up a lightweight Nginx web container:

mkdir -p ~/nginx-test && cd ~/nginx-test

Create a compose.yml file:

cat <<'EOF' > compose.yml
services:
  web:
    image: nginx:alpine
    container_name: test-nginx
    ports:
      - "8080:80"
    restart: unless-stopped
EOF

Start the container in detached mode and verify it is running:

docker compose up -d
docker compose ps
curl -I http://localhost:8080

When you see HTTP/1.1 200 OK, tear down the test environment cleanly:

docker compose down
cd ~ && rm -rf ~/nginx-test

3 Essential Post-Installation Settings for Production VPS Use

Before deploying live workloads after learning how to install Docker on Ubuntu, apply these three quick configurations to prevent disk bloat, avoid firewall bypasses, and simplify reverse proxy routing.

1. Enable Docker Log Rotation to Prevent Full Disks

By default, Docker stores container JSON logs with no size limit. A noisy web app or database can silently fill your NVMe drive over a few months—one of the classic issues covered in our common VPS mistakes guide. Cap container log sizes globally by creating /etc/docker/daemon.json:

sudo tee /etc/docker/daemon.json > /dev/null <<'EOF'
{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  }
}
EOF

sudo systemctl restart docker

2. Bind Internal Container Ports to 127.0.0.1

When you map a port using "8080:80" in Docker, Docker modifies Linux iptables rules directly and exposes port 8080 to the public internet—even if UFW is active. Whenever you place an Nginx or Caddy reverse proxy in front of a container, bind the port to localhost instead ("127.0.0.1:8080:80") so external traffic can only reach your app over HTTPS through your proxy. Keeping internal services bound to loopback ensures your firewall stays in full control while keeping backend databases and APIs completely isolated from external scanners.

3. Create a Dedicated Bridge Network for Reverse Proxies

When hosting multiple containerized web apps on one VPS, avoid exposing dozens of ports on your host interface. Creating a user-defined Docker bridge network allows containers—such as an Nginx Proxy Manager or Caddy reverse proxy—to communicate securely using container names as internal hostnames:

docker network create proxy-net

Any container attached to proxy-net can reach other services on the same network internally without opening extra ports to the public internet.

Essential Docker and Docker Compose Commands for Daily VPS Management

After completing how to install Docker on Ubuntu, keep these everyday commands handy for monitoring containers, viewing logs, and applying updates without downtime:

  • Stream live container logs: Run docker compose logs -f inside your project directory to watch real-time application output and troubleshoot startup errors immediately.
  • Update containers to the latest image: Pull fresh upstream builds and recreate running services cleanly with docker compose pull && docker compose up -d.
  • Monitor live CPU and RAM usage: Run docker stats --no-stream to check how much memory and processor capacity each running container consumes on your VPS.
  • Inspect container disk consumption: Run docker system df to see how much NVMe storage images, stopped containers, and persistent volumes occupy.
  • Restart a single service: Run docker compose restart web (replacing web with your service name) to reload configuration changes in seconds without restarting your database.

Frequently Asked Questions About How to Install Docker on Ubuntu

Why shouldn’t I use sudo apt install docker.io?

When researching how to install Docker on Ubuntu, you will often see apt install docker.io mentioned in older posts. That package is maintained by Ubuntu rather than Docker Inc., often lags behind upstream security and feature releases, and does not include the modern docker-compose-plugin or Buildx tools.

What is the difference between docker-compose and docker compose?

docker-compose (with a hyphen) was the legacy standalone Python v1 tool, which reached End-of-Life in 2023. Following the official steps on how to install Docker on Ubuntu installs Docker Compose v2 (docker compose with a space), which is written in Go, runs faster, and integrates natively into the Docker CLI.

How much RAM do I need to run Docker on an Ubuntu VPS?

Docker Engine itself consumes under 100 MB of idle RAM, so you can easily run lightweight containers (such as Uptime Kuma, WireGuard, or static sites) on a 1 GB RAM VPS with a 2 GB swap file. For multi-container stacks involving PostgreSQL, MySQL, Redis, or n8n, choose a 2 GB to 4 GB RAM VPS for smooth performance.

How do I upgrade Docker Engine after completing how to install Docker on Ubuntu?

Because you configured Docker’s official APT repository during how to install Docker on Ubuntu, updating Docker Engine and Docker Compose happens automatically alongside your regular system updates. Run sudo apt update && sudo apt upgrade -y to pull the latest security patches and engine releases.

How do I reclaim disk space from old Docker images and containers?

Stopped containers, dangling image layers, and unused build caches accumulate over time. Run docker system df to inspect disk usage, and run docker system prune -a periodically to remove unused images and free up NVMe storage—or check our Linux server troubleshooting guide if your disk fills unexpectedly.

Conclusion

Mastering how to install Docker on Ubuntu 24.04 LTS gives your VPS a reliable, standardized foundation for deploying almost any modern web application or self-hosted service. By using Docker’s official APT repository, configuring non-root group access, and enabling JSON log rotation, your server stays clean, secure, and ready for production containers.

Bookmark this guide on how to install Docker on Ubuntu for your next server setup, and start deploying multi-container apps in minutes with Docker Compose v2.