· 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.

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 sudo privileges
  • 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 -y

Step 2: Install Required Dependencies

Install the packages needed to add a new apt repository over HTTPS:

sudo apt-get install -y ca-certificates curl

Step 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.asc

Step 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/null

Then update your package index again to include the Docker packages:

sudo apt-get update

Step 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-plugin

Step 6: Start and Enable Docker

Start the Docker service and enable it to launch automatically on boot:

sudo systemctl start docker
sudo systemctl enable docker

Verify Docker is running:

sudo systemctl status docker

You 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-world

If Docker is installed correctly, you’ll see a message confirming that the installation is working.

Check the installed version:

docker --version
docker compose version

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 $USER

Apply the group change without logging out:

newgrp docker

Test it:

docker run hello-world

Security note: Users in the docker group 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 nginx

Then open your browser or use curl:

curl http://localhost:8080

You should see the Nginx welcome page.

Stop and remove the container when done:

docker stop my-nginx
docker rm my-nginx

Useful Docker Commands

CommandDescription
docker psList running containers
docker ps -aList all containers (including stopped)
docker imagesList downloaded images
docker pull nginxDownload 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> bashOpen 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.asc

Summary

Here’s what you did:

  1. Updated the system and installed dependencies
  2. Added Docker’s official GPG key and repository
  3. Installed Docker Engine, CLI, containerd, and Compose
  4. Started and enabled the Docker service
  5. Configured Docker to run without sudo
  6. 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
Share:
Back to Blog

Related Posts

View All Posts »