How to Install Docker on Ubuntu 24.04: A Complete Step-by-Step Guide

March 4, 2026
Views 18
Comments0

Table of contents

Docker is a platform that allows you to run applications in isolated environments called containers. Containers are lighter and faster than virtual machines, fundamentally solving problems caused by differences between development and production environments. This guide walks you through the entire process of installing Docker on Ubuntu 24.04 and running your first container, step by step.

Prerequisites

  • An Ubuntu 24.04 server (local or cloud)
  • A user account with sudo privileges
  • An internet connection

First, make sure your server is up to date.

sudo apt update && sudo apt upgrade -y

Step 1: Install Required Packages

Install the dependency packages needed to access the Docker repository over HTTPS.

sudo apt install apt-transport-https ca-certificates curl software-properties-common -y

Step 2: Add Docker GPG Key

Register the GPG key to verify the integrity of official Docker packages.

sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc

Step 3: Add Docker Repository

Add the official Docker repository to Ubuntu's APT source list.

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

Step 4: Install Docker

Update the repository and install the Docker engine along with its related tools.

sudo apt update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
Installed Components
  • docker-ce: Docker Engine (core daemon)
  • docker-ce-cli: Command-line interface
  • containerd.io: Container runtime
  • docker-buildx-plugin: Multi-platform build support
  • docker-compose-plugin: Multi-container orchestration

Once installation is complete, verify the version.

sudo docker --version

Step 5: Manage the Docker Service

Configure Docker to start automatically when the server reboots.

sudo systemctl enable docker
sudo systemctl start docker
Command Description
sudo systemctl status dockerCheck Docker service status
sudo systemctl stop dockerStop Docker service
sudo systemctl restart dockerRestart Docker service
sudo systemctl enable dockerEnable auto-start on boot

Step 6: Run Your First Container

Run an Nginx web server container to verify that Docker is working properly.

# Pull the Nginx image
sudo docker pull nginx:latest

# Run the container (host port 80 → container port 80)
sudo docker run --name mynginx -d -p 80:80 nginx:latest

# Check running containers
sudo docker ps

After allowing port 80 through the firewall, open your browser and navigate to your server's IP address to see the default Nginx page.

sudo ufw allow 80/tcp

Commonly Used Docker Commands

Command Description
docker psList running containers
docker ps -aList all containers (including stopped)
docker imagesList local images
docker stop [name]Stop a container
docker rm [name]Remove a container
docker rmi [image]Remove an image
docker logs [name]View container logs
docker exec -it [name] bashAccess a container shell

Running Docker Without sudo

If typing sudo every time feels cumbersome, add your current user to the docker group.

sudo usermod -aG docker $USER
newgrp docker

After logging out and back in, you can use Docker commands without sudo.

Caution: Users in the docker group effectively have root-level access to the system. Apply this carefully on production servers, considering your security policies.
Note for GPU servers: Cloud instances with NVIDIA GPUs often come with Docker and the NVIDIA Container Toolkit pre-installed. Reinstalling Docker separately may cause conflicts with GPU drivers, so always check for an existing installation first.
Comments 0