· Sysadmin.id · Linux · 3 min read
How to Install Docker on Ubuntu 24.04 LTS
A complete step-by-step guide to installing Docker Engine on Ubuntu 24.04 LTS (Noble Numbat) — from adding the official repository to running your first container and setting up Docker Compose.
Docker is the industry-standard platform for building, shipping, and running containerized applications. This guide walks you through installing Docker Engine on Ubuntu 24.04 LTS (Noble Numbat) using Docker’s official repository — the recommended method for production systems.
Prerequisites
Before you begin, make sure you have:
- A server or VM running Ubuntu 24.04 LTS
- A user with
sudoprivileges - Internet access
Note: Do not use the Docker version from Ubuntu’s default apt repository (
apt install docker.io). It’s outdated. Always install from Docker’s official repository.
Step 1: Update the System
Start by updating your package index to make sure everything is current:
sudo apt-get update && sudo apt-get upgrade -yStep 2: Install Required Dependencies
Install the packages needed to add a new apt repository over HTTPS:
sudo apt-get install -y ca-certificates curlStep 3: Add Docker’s Official GPG Key
Create the keyrings directory and download Docker’s GPG 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.ascStep 4: Add the Docker Repository
Add Docker’s stable repository to your apt sources:
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/nullThen update your package index again to include the Docker packages:
sudo apt-get updateStep 5: Install Docker Engine
Install Docker Engine, the CLI, containerd, and the Buildx and Compose plugins:
sudo apt-get install -y \
docker-ce \
docker-ce-cli \
containerd.io \
docker-buildx-plugin \
docker-compose-pluginStep 6: Start and Enable Docker
Start the Docker service and enable it to launch automatically on boot:
sudo systemctl start docker
sudo systemctl enable dockerVerify Docker is running:
sudo systemctl status dockerYou should see Active: active (running) in the output.
Step 7: Verify the Installation
Run the official hello-world image to confirm Docker is working correctly:
sudo docker run hello-worldIf Docker is installed correctly, you’ll see a message confirming that the installation is working.
Check the installed version:
docker --version
docker compose versionStep 8: Run Docker Without sudo (Recommended)
By default, Docker requires sudo. To run Docker commands as a non-root user, add your user to the docker group:
sudo usermod -aG docker $USERApply the group change without logging out:
newgrp dockerTest it:
docker run hello-worldSecurity note: Users in the
dockergroup have root-equivalent privileges on the host. Only add trusted users.
Step 9: Test with a Real Container
Let’s run a real-world example — an Nginx web server:
docker run -d -p 8080:80 --name my-nginx nginxThen open your browser or use curl:
curl http://localhost:8080You should see the Nginx welcome page.
Stop and remove the container when done:
docker stop my-nginx
docker rm my-nginxUseful Docker Commands
| Command | Description |
|---|---|
docker ps | List running containers |
docker ps -a | List all containers (including stopped) |
docker images | List downloaded images |
docker pull nginx | Download an image |
docker stop <id> | Stop a running container |
docker rm <id> | Remove a stopped container |
docker rmi <image> | Remove an image |
docker logs <id> | View container logs |
docker exec -it <id> bash | Open a shell inside a container |
Uninstall Docker (if needed)
To completely remove Docker from your system:
sudo apt-get purge -y docker-ce docker-ce-cli containerd.io \
docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras
sudo rm -rf /var/lib/docker
sudo rm -rf /var/lib/containerd
sudo rm /etc/apt/sources.list.d/docker.list
sudo rm /etc/apt/keyrings/docker.ascSummary
Here’s what you did:
- Updated the system and installed dependencies
- Added Docker’s official GPG key and repository
- Installed Docker Engine, CLI, containerd, and Compose
- Started and enabled the Docker service
- Configured Docker to run without
sudo - Verified the installation with a real container
Docker is now ready on your Ubuntu 24.04 server. From here you can start containerizing applications, writing docker-compose.yml files, and building your own images with Dockerfiles.
Need help setting up Docker for your infrastructure? Get in touch — I’m happy to help.
- docker
- ubuntu
- linux
- containers
- devops