TutorialsAugust 4, 20264 min read

How to Install Docker on Ubuntu 24.04

Install Docker Engine the official way on Ubuntu 24.04, run it without sudo, and verify with hello-world. Clean, current commands.

NBy Nxeon

Docker lets you package and run applications in containers — isolated, reproducible, and easy to move between machines. This guide installs Docker Engine on Ubuntu 24.04 using Docker's official repository (not the outdated docker.io apt package), sets it up to run without sudo, and verifies everything works.

Why the official repo, not apt's docker.io?

Ubuntu's built-in docker.io package is older and misses the modern Compose plugin. Installing from Docker's own repository gets you current Docker Engine plus docker compose v2 as a first-class subcommand. It is a few more steps, worth it every time.

Remove any old versions

Clear out conflicting packages first:

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

Add Docker's official repository

Set up the apt keyring and source:

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

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

Install Docker Engine

Install the engine, CLI, containerd, and the Compose and Buildx plugins:

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

The service starts and enables automatically. Verify with the classic test image:

sudo docker run hello-world

If you see the "Hello from Docker!" message, the engine is working.

Building a website with Claude AI inside the Nxeon control panel
Building a website with Claude AI inside the Nxeon control panel

Run Docker without sudo

Typing sudo before every docker command gets old fast. Add your user to the docker group:

sudo usermod -aG docker $USER
newgrp docker

Log out and back in (or run newgrp docker) for the group change to apply. Now docker run hello-world works without sudo. Be aware: the docker group is effectively root-equivalent, so only add trusted users.

A quick real container

Run Nginx in a container mapped to port 8080:

docker run -d --name web -p 8080:80 nginx
curl http://127.0.0.1:8080
docker ps

Stop and remove it when done:

docker stop web && docker rm web

Useful housekeeping commands

  • List running containers: docker ps
  • List all containers: docker ps -a
  • List images: docker images
  • View logs: docker logs web
  • Reclaim space: docker system prune -a

Where to go next

A single docker run is fine for one container, but real apps have several — a web server, a database, a cache. That is what Docker Compose is for. For a visual dashboard to manage it all, install Portainer. And remember to open only the ports you need in UFW — Docker can bypass UFW rules, so bind published ports to 127.0.0.1 when a service should stay private.

Images, containers, and volumes

Three concepts unlock Docker. An image is a read-only template (like nginx or postgres:16); a container is a running instance of an image; a volume is persistent storage that outlives containers. Containers are disposable by design — delete one and recreate it freely. Anything you need to keep, from database files to uploads, belongs in a volume:

docker volume create appdata
docker run -d --name db -v appdata:/var/lib/postgresql/data postgres:16

Now the container can be removed and recreated and the data survives in the appdata volume.

Keep the disk under control

Images, stopped containers, and dangling volumes accumulate quietly and can fill a small VPS. Check usage and reclaim space periodically:

docker system df
docker system prune -a --volumes

The second command is aggressive — it removes everything not currently in use — so run it deliberately. Watching docker system df alongside df -h keeps disk surprises at bay.

FAQ

Do I still need Docker Compose as a separate install?

No. The docker-compose-plugin installed above gives you docker compose (with a space) as a built-in subcommand. The old standalone docker-compose binary is legacy.

Why does Docker seem to ignore my UFW firewall rules?

Docker writes its own iptables rules that can publish container ports past UFW. The safe fix is to bind sensitive ports to localhost (-p 127.0.0.1:5432:5432) so they are never exposed publicly.

How do I make containers restart after a reboot?

Add a restart policy: docker run -d --restart unless-stopped .... Containers with that policy come back automatically when the Docker service starts on boot.

Is Docker a good fit for a small VPS?

Yes, containers are lightweight. Just watch disk usage — images and volumes accumulate. Run docker system prune periodically and keep an eye on space with df -h.

Nxeon Docker hosting gives you a VPS with full root and one-click Docker-ready Ubuntu images, so you can go from fresh server to running containers in minutes — with free migration help if you are moving a stack across.

#docker#ubuntu#vps#containers#devops#seobatch

Deploy your first server in under a minute

Creating an account is free and takes no card details. You pay when you deploy — choose a billing term and pay from your wallet or by card at checkout.