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

Table of contents
- Prerequisites
- Step 1: Install Required Packages
- Step 2: Add Docker GPG Key
- Step 3: Add Docker Repository
- Step 4: Install Docker
- Step 5: Manage the Docker Service
- Step 6: Run Your First Container
- Commonly Used Docker Commands
- Running Docker Without sudo
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 -yStep 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 -yStep 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.ascStep 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/nullStep 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- 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 --versionStep 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 docker | Check Docker service status |
sudo systemctl stop docker | Stop Docker service |
sudo systemctl restart docker | Restart Docker service |
sudo systemctl enable docker | Enable 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 psAfter 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/tcpCommonly Used Docker Commands
| Command | Description |
|---|---|
docker ps | List running containers |
docker ps -a | List all containers (including stopped) |
docker images | List 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] bash | Access 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 dockerAfter logging out and back in, you can use Docker commands without sudo.

Comments 0개
No comments yet.