Docker packages an application with everything it needs, so it runs the same on your laptop and on every server. This guide installs Docker Engine with the Compose and Buildx plugins on Ubuntu 24.04 LTS (Noble Numbat) from Docker's own repository, then covers the settings people usually discover too late: who can run Docker, how published ports interact with the firewall, and log rotation.
Prerequisites
- A server running Ubuntu 24.04, 64-bit (x86_64 or arm64).
- A user with
sudorights. - The UFW firewall enabled with SSH allowed.
Step 1 — Remove conflicting packages
Ubuntu's own docker.io package and similar tools conflict with Docker's official packages. Remove any that exist (apt may say none are installed — that's fine):
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove -y $pkg; doneExisting images and containers in /var/lib/docker/ are not deleted by this step.
Step 2 — Add Docker's repository
Add Docker's signing key and its repository. The Suites line reads your release's codename automatically — on Ubuntu 24.04 it becomes noble:
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
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 updateStep 3 — Install Docker Engine
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-pluginThe service starts automatically. Check it, and run the test image:
sudo systemctl status docker --no-pager
sudo docker run --rm hello-worldHello from Docker!
This message shows that your installation appears to be working correctly.Step 4 — Run Docker without sudo (understand the risk)
Adding your user to the docker group lets you run docker without sudo:
sudo usermod -aG docker $USER
newgrp docker
docker psStep 5 — Published ports bypass UFW
When you publish a port with -p 8080:80, Docker writes its own firewall rules, and UFW does not block that port. Many servers are exposed this way by accident. Publish services that sit behind a reverse proxy on localhost only:
docker run -d --name web -p 127.0.0.1:8080:80 nginx:stableThen let your reverse proxy (nginx, Caddy) on the host forward public traffic to 127.0.0.1:8080. Publish a port on all interfaces only when you really want it open to the internet.
Step 6 — Rotate container logs
By default, container logs can grow until the disk is full. Switch to Docker's local log driver, which compresses and rotates logs, in /etc/docker/daemon.json:
{
"log-driver": "local",
"log-opts": { "max-size": "20m", "max-file": "5" }
}sudo systemctl restart dockerThe new settings apply to containers created after the restart.
Step 7 — Use Docker Compose
Compose describes several containers in one file. Create compose.yaml:
services:
app:
image: nginx:stable
ports:
- "127.0.0.1:8080:80"
restart: unless-stoppeddocker compose up -d
docker compose psKeeping Docker up to date
Docker updates arrive through apt with the rest of the system:
sudo apt update && sudo apt upgrade -yClean up unused images and stopped containers from time to time with docker system prune (it asks before deleting).
Conclusion
Docker Engine, Compose and Buildx are now installed on Ubuntu 24.04, with safe defaults for permissions, ports and logs. Ubuntu 24.04 receives standard security updates until 31 May 2029 — plan your next server move well before then.