How to Install Docker on Ubuntu 24.04: Step‑By‑Step Guide
Introduction to Docker on Ubuntu 24.04 Noble Numbat
What is Docker?
Docker is a platform that packages an application together with everything it needs—libraries, runtime, system tools—into a single, portable container. The container runs the same way on any Linux host that has Docker installed, eliminating the “it works on my machine” problem.
Why Use Docker on Ubuntu 24.04 Noble Numbat?
Ubuntu 24.04 is the newest LTS release, bringing cgroups v2, nftables as the default firewall, and a modern kernel that Docker leverages for better performance and security. Installing Docker from the official repository gives you the latest engine, containerd 2.x, and BuildKit support out of the box.
Prerequisites and System Requirements
Hardware Requirements
- 64‑bit processor (Intel x86_64 or ARM64)
- At least 2 GB RAM (4 GB recommended for development)
- Minimum 10 GB of free disk space for images and containers
Updating Your System Package Index
Before adding new repositories, make sure the local package cache is fresh.
sudo apt update && sudo apt upgrade -y Installing Necessary Dependencies
Docker needs a few helper packages for HTTPS and certificate handling.
sudo apt install -y ca-certificates curl gnupg lsb-release Step‑By‑Step Guide to Installing Docker Engine
Adding the Official Docker GPG Key
Docker signs its packages with a GPG key. Store the key in /etc/apt/keyrings and bind it to the repository.
sudo mkdir -p /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg sudo chmod a+r /etc/apt/keyrings/docker.gpg Setting Up the Stable Docker Repository
Use the lsb_release command to insert the correct codename (Noble).
echo \ "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \ https://download.docker.com/linux/ubuntu \ $(lsb_release -cs) stable" | \ sudo tee /etc/apt/sources.list.d/docker.list > /dev/null Installing Docker Engine, CLI, and Containerd
sudo apt update sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin The docker-compose-plugin provides the modern docker compose command (Compose V2) directly integrated with the Docker CLI.
Verifying the Docker Installation
Check that the daemon is running and pull the test image.
sudo systemctl status docker --no-pager docker run --rm hello-world If the container prints a friendly greeting, Docker is ready.
Post‑Installation Configuration
Managing Docker as a Non‑Root User
Docker groups grant root‑equivalent access, so add yourself to the group and re‑login.
sudo usermod -aG docker $USER newgrp docker # optional, applies group change without logout Test the setup:
docker ps Configuring Docker to Start on Boot
sudo systemctl enable docker sudo systemctl start docker Installing Docker Compose (optional)
If you prefer the legacy Python binary, you can install it, but the integrated plugin is already present. For completeness:
sudo curl -L "https://github.com/docker/compose/releases/download/v2.24.5/docker-compose-$(uname -s)-$(uname -m)" \ -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose docker compose version # should report v2.x Docker Best Practices for Ubuntu Users
Optimizing Storage Drivers
Ubuntu 24.04 defaults to overlay2, which works well on ext4 and XFS. If you run on ZFS or Btrfs, set the driver explicitly:
sudo mkdir -p /etc/docker cat > /etc/docker/daemon.json <<EOF { "storage-driver": "overlay2" } EOF sudo systemctl restart docker Managing Container Resource Limits
With cgroups v2 active, you can limit CPU and memory per container directly in the run command:
docker run -d --name web \ --cpus="1.5" --memory="500m" \ nginx:latest Securing Your Docker Daemon
- Enable Docker Content Trust:
export DOCKER_CONTENT_TRUST=1(or add to~/.bashrc). - Run a security audit with the official benchmark image:
docker run -it --net host --pid host \ -v /var/lib/docker:/var/lib/docker \ -v /etc:/etc \ -v /usr/bin/docker:/usr/bin/docker \ docker/docker-bench-security Common Installation Issues and Troubleshooting
Fixing GPG Key Errors
If apt complains about a missing public key, re‑download the key and ensure the signed-by reference matches the file path.
Resolving Permission Denied Errors
Typical cause: the user isn’t in the docker group or the socket permissions are wrong.
ls -l /var/run/docker.sock # Expected: srw-rw---- 1 root docker … /var/run/docker.sock Adjust with:
sudo chown root:docker /var/run/docker.sock sudo chmod 660 /var/run/docker.sock Handling Network Connectivity Issues
Ubuntu 24.04 ships with nftables; Docker still relies on iptables. If you see “network is unreachable” inside containers, either switch the kernel to use iptables-legacy or tell Docker to use the nftables backend.
sudo update-alternatives --set iptables /usr/sbin/iptables-legacy sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy sudo systemctl restart docker Alternatively, add a Docker‑specific rule set to /etc/nftables.conf and reload.