🛠️ ITBlogs.pro

How to Install Docker on Ubuntu 24.04 (Official Repository)

Oct 16, 2026 · Docker · 3 min read

Ubuntu's own docker.io package is often outdated. For a current Docker Engine, Compose and Buildx, use Docker's official apt repository. This takes about five minutes on Ubuntu 24.04 LTS.

1. Remove conflicting packages

Skip this on a fresh server. It's harmless if nothing is installed:

sudo apt remove -y docker.io docker-compose docker-compose-v2 docker-doc podman-docker containerd runc

This does not delete existing images, containers or volumes in /var/lib/docker.

2. Add Docker's repository

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

3. Install

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

4. Verify

sudo systemctl status docker --no-pager
sudo docker run --rm hello-world
docker --version
docker compose version

The service is enabled at boot automatically. Note that the command is docker compose (with a space); the old docker-compose is the obsolete v1.

5. Run Docker without sudo (optional, read the warning)

sudo usermod -aG docker $USER
newgrp docker            # or log out and back in
docker ps

Warning: anyone in the docker group is effectively root on the machine, because they can start a container that mounts the whole filesystem. Only add users you fully trust, and never on a shared server.

6. Limit log size (important on small disks)

By default container logs grow without limit and can fill the disk. Cap them for all new containers:

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

Existing containers keep their old settings until they're recreated.

7. Know where the data lives

Everything (images, containers, volumes) is stored in /var/lib/docker. Include your volumes in backups, and watch the disk:

docker system df

8. Security note: Docker and your firewall

Published ports (-p 8080:80) go around UFW. A rule such as ufw deny 8080 will not protect a container. Read Docker and UFW: published ports bypass the firewall before you expose anything to the internet.

Updating and removing

Docker updates come with normal apt upgrade. Upgrading the engine restarts the Docker daemon, which stops running containers unless live-restore is enabled. Containers that have a restart policy come back up on their own.

To remove it completely:

sudo apt purge -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo rm -rf /var/lib/docker /var/lib/containerd     # deletes ALL images, containers and volumes