Quick take: Docker has become an essential tool in modern software development and deployment pipelines.

Installing Docker on Ubuntu 24.04 Step-by-Step

Docker has become an essential tool in modern software development and deployment pipelines. Ubuntu 24.04 LTS is one of the most popular Linux distributions for running containerized applications, making it the ideal choice for DevOps engineers and developers looking to leverage Docker's powerful containerization capabilities. This comprehensive guide will walk you through the complete process of installing Docker on Ubuntu 24.04, covering prerequisites, installation methods, configuration, and verification steps.

Whether you are setting up a development environment, preparing a production server, or building a container orchestration platform, understanding how to properly install Docker on Ubuntu 24.04 is a fundamental skill. This article provides detailed instructions that cater to both beginners and experienced IT professionals.

Understanding Docker and System Requirements

What is Docker and Why Use It

Docker is a containerization platform that allows you to package applications with their dependencies into lightweight, portable containers. A container is essentially a standalone package that includes everything needed to run an application: code, runtime, system tools, libraries, and settings. Unlike virtual machines that virtualize the entire operating system, Docker containers share the host OS kernel, making them more efficient in terms of resource consumption and startup time.

The benefits of using Docker include reduced deployment times, consistency across development and production environments, simplified scaling, improved resource utilization, and streamlined microservices architecture implementation. For DevOps teams in Riyadh and across the Middle East, Docker provides a standardized approach to managing applications across different infrastructures.

Ubuntu 24.04 LTS Advantages

Ubuntu 24.04 LTS (Long Term Support) is the latest long-term support version, offering five years of standard support and additional extended security maintenance. This version includes improved package management, updated kernel versions, and better hardware support. LTS versions are ideal for production environments where stability and predictability are paramount.

Ubuntu 24.04 comes with Python 3.12, an updated Linux kernel, and enhanced container support built into the OS. These features make it an excellent choice for running Docker containers in enterprise environments.

System Requirements for Docker Installation

Before installing Docker on Ubuntu 24.04, ensure your system meets the following requirements:

  • A 64-bit processor with virtualization support (VT-x for Intel, AMD-V for AMD)
  • Minimum 2GB RAM (4GB or more recommended for production)
  • At least 20GB free disk space
  • Ubuntu 24.04 LTS properly installed and updated
  • User account with sudo privileges
  • Stable internet connection for downloading Docker packages
  • Access to a terminal or SSH connection

To verify your system supports virtualization, run the following command:

grep -E 'vmx|svm' /proc/cpuinfo | head -1

If this command returns output containing "vmx" (Intel) or "svm" (AMD), your processor supports virtualization.

Pre-Installation Steps and System Preparation

Updating the System

The first critical step is updating your Ubuntu system to the latest package versions. This ensures you have the latest security patches and compatibility fixes.

sudo apt update
sudo apt upgrade -y
sudo apt autoremove -y

Breaking down these commands: apt update refreshes the package index from all repositories, apt upgrade upgrades all installed packages to their newest versions, and apt autoremove removes any unused packages that were dependencies of previously removed packages. The -y flag automatically answers "yes" to prompts, useful for automated deployments.

Installing Prerequisites and Dependencies

Docker requires certain packages to function properly. Install the necessary dependencies:

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

Here is what each package provides:

  • ca-certificates: Contains the common CA certificates for SSL/TLS validation
  • curl: Command-line tool for downloading files and making HTTP requests
  • gnupg: GNU Privacy Guard for verifying cryptographic signatures
  • lsb-release: Identifies your Linux distribution and version
  • apt-transport-https: Allows apt to retrieve packages over HTTPS
  • software-properties-common: Provides scripts for managing software repositories

Removing Old Docker Installations

If you have previously installed Docker on this system using a different method, remove the old installation to avoid conflicts:

sudo apt remove -y docker docker-engine docker.io containerd runc docker-compose

This command ensures a clean slate for the new Docker installation. Even if these packages are not installed, running this command is safe and creates no errors.

Method 1: Installing Docker from Official Docker Repository

Adding Docker's GPG Key

The official Docker repository uses cryptographic signatures to ensure package authenticity. Download and add Docker's GPG key to your system:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

This command downloads Docker's GPG key and converts it from ASCII armored format to binary format, storing it in the system's keyring directory. The flags used are: -f (fail on server errors), -s (silent mode), -S (show errors), and -L (follow redirects).

Adding Docker Repository

Now add the official Docker repository to your system's package sources:

echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

This command creates a new entry in the APT sources list. Let me break it down: $(lsb_release -cs) automatically detects your Ubuntu codename (noble for Ubuntu 24.04), and signed-by= specifies the GPG key for verifying packages. The stable channel provides the latest stable releases of Docker.

Update the package index again to include packages from the Docker repository, then install Docker Engine:

sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

These packages include:

  • docker-ce: Docker Community Edition, the main Docker engine
  • docker-ce-cli: Command-line interface for Docker
  • containerd.io: Container runtime that Docker uses at its core
  • docker-buildx-plugin: Extended build capabilities supporting multi-platform builds
  • docker-compose-plugin: Modern Docker Compose (V2) for multi-container orchestration

Method 2: Installing Docker Using Convenience Script

When to Use the Convenience Script

Docker provides an official convenience script for quick installation in development and testing environments. While not recommended for production systems, it streamlines the installation process significantly. This method is useful for rapid deployment in non-critical environments, CI/CD pipelines, or initial testing.

Running the Convenience Script

Download and execute Docker's official installation script:

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

Alternatively, you can execute it directly without saving:

curl -fsSL https://get.docker.com | sudo sh

This script automatically detects your Ubuntu version, adds the Docker repository, and installs all necessary components. It is the fastest method but provides less control over the installation process compared to the repository method.

Uninstalling if Using Convenience Script

If you need to remove Docker installed via the convenience script, use your package manager:

sudo apt remove -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Post-Installation Configuration

Starting and Enabling Docker Service

After installation, Docker runs as a systemd service. Start Docker and enable it to automatically start on system boot:

sudo systemctl start docker
sudo systemctl enable docker
sudo systemctl status docker

The status command displays the current state of the Docker daemon. You should see "Active: active (running)" in the output. The enable command creates necessary symlinks so Docker starts automatically when the system boots.

Configuring User Permissions

By default, Docker requires root privileges. To run Docker commands without using sudo, add your user to the docker group:

sudo usermod -aG docker $USER

Apply the new group membership without logging out:

newgrp docker

Verify that Docker commands work without sudo:

docker ps

Important security note: Users in the docker group have privileges equivalent to the root user. Only add trusted users to the docker group, and never grant docker group access to untrusted users.

Configuring Docker Daemon

The Docker daemon configuration file controls Docker's behavior. Create or edit the configuration file:

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json > /dev/null <

This configuration provides sensible defaults: disables debug mode (set to true for troubleshooting), configures JSON file logging with rotation, and specifies the overlay2 storage driver which is the modern standard offering better performance than older drivers.

Reload the daemon to apply changes:

sudo systemctl daemon-reload
sudo systemctl restart docker

Verifying Your Docker Installation

Running Docker Version Check

Verify that Docker installed correctly and check its version:

docker --version
docker version

The --version flag displays concise version information. The version command provides detailed information about both the client and server components, showing their respective versions and build details.

Running Hello World Container

The definitive test of a working Docker installation is running the official hello-world container:

docker run hello-world

This command pulls the tiny hello-world image from Docker Hub (Docker's official image registry) and runs it. Successful output indicates that Docker can retrieve images and execute containers properly. If this command succeeds, your Docker installation is functioning correctly.

Checking Docker System Information

Get detailed information about your Docker installation and system:

docker info

This command displays comprehensive information including number of containers and images, storage driver and location, logging driver, kernel version, and OS details. This information is invaluable for diagnostics and verifying proper configuration.

Running a More Complex Test Container

Test Docker with a more substantial container to ensure everything works properly:

docker run -it ubuntu:24.04 bash

This command runs an interactive bash shell inside an Ubuntu 24.04 container. The -i flag keeps stdin open even when not attached, and -t allocates a pseudo-terminal. You now have a shell inside a containerized Ubuntu environment. Type exit to leave the container.

Installing Docker Compose Standalone

Understanding Docker Compose Versions

Docker Compose exists in two forms: the plugin version (included with modern Docker installations) and the standalone version. The plugin version (docker-compose-plugin package) is integrated with Docker and accessed via docker compose command. The standalone version is a separate binary accessed via docker-compose command (with hyphen).

For most users, the plugin version installed earlier is sufficient. However, some legacy scripts or specific use cases may require the standalone version.

Installing Standalone Docker Compose Binary

If you need the standalone version, download it from the official GitHub releases:

sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version

This downloads the latest release matching your system's OS and architecture, makes it executable, and verifies the installation. The $(uname -s) returns your OS (Linux), and $(uname -m) returns your architecture (x86_64 for most systems).

Setting Up Docker for Development

Creating Your First Docker Image

Create a simple application directory and Dockerfile to build your first custom image:

mkdir -p ~/docker-projects/myapp
cd ~/docker-projects/myapp

Create a simple Python application:

cat > app.py << 'EOF'
#!/usr/bin/env python3
import socket
import os

hostname = socket.gethostname()
container_id = os.environ.get('CONTAINER_ID', 'unknown')

print(f"Hello from Docker!")
print(f"Hostname: {hostname}")
print(f"Container ID: {container_id}")
EOF

Create a Dockerfile to containerize this application:

cat > Dockerfile << 'EOF'
FROM python:3.12-slim

WORKDIR /app

COPY app.py .

ENV CONTAINER_ID=demo-container

ENTRYPOINT ["python3", "app.py"]
EOF

Build the image:

docker build -t myapp:latest .

Run the container:

docker run myapp:latest

You should see output showing the application running inside a container with a different hostname than your host system, proving containerization is working.

Managing Container Images and Containers

List all Docker images on your system:

docker images

List all containers (running and stopped):

docker ps -a

Remove unused images and containers to save disk space:

docker system prune -a

This command removes all stopped containers, unused images, and dangling images. Add --volumes to also remove unused volumes, but use this carefully as it will delete volume data.

Troubleshooting Common Installation Issues

Docker Daemon Not Starting

If the Docker daemon fails to start, check the systemd journal for errors:

sudo journalctl -u docker --no-pager | tail -50

Common causes include insufficient disk space, SELinux/AppArmor restrictions, or port conflicts. Check available disk space:

df -h

Ensure at least 2GB free disk space. If disk space is the issue, remove unused packages and clean the package cache:

sudo apt clean
sudo apt autoclean
sudo apt autoremove

Permission Denied Errors

If you receive "permission denied" errors after adding your user to the docker group, you may need to reset the group membership:

sudo usermod -aG docker $USER
exec newgrp docker

Alternatively, log out and log back in for the group changes to take effect system-wide.

Network Connectivity Issues

If containers cannot reach the internet, verify that Docker's network bridge is properly configured:

docker network ls
docker network inspect bridge

Check that the host system has internet connectivity and that UFW firewall rules are not blocking Docker:

sudo ufw status
sudo ufw allow 2375/tcp
sudo systemctl restart docker

Image Pull Failures

If Docker cannot pull images from Docker Hub, verify your internet connection and DNS resolution:

ping 8.8.8.8
nslookup hub.docker.com

If DNS resolution fails, configure alternate DNS servers in the Docker daemon configuration:

sudo tee /etc/docker/daemon.json > /dev/null <

Security Best Practices After Installation

Securing Docker Daemon Socket

The Docker socket at /var/run/docker.sock controls Docker access. Restrict its permissions to prevent unauthorized access:

ls -la /var/run/docker.sock

The socket should be owned by root with group docker. Only add necessary users to the docker group.

Setting Resource Limits

Configure default resource limits for containers to prevent resource exhaustion:

sudo tee /etc/docker/daemon.json > /dev/null <

Using AppArmor Profiles

Ubuntu uses AppArmor for mandatory access control. Verify Docker AppArmor profiles are loaded:

sudo aa-status | grep docker

Docker ships with AppArmor profiles for container isolation. Ensure these profiles are active for enhanced security.

Updating and Maintaining Docker

Upgrading Docker to Latest Version

Keep Docker up to date for security patches and new features:

sudo apt update
sudo apt upgrade -y docker-ce docker-ce-cli containerd.io

Check for updates regularly. You can automate this using unattended-upgrades for production systems.

Checking for Orphaned Resources

Regularly clean up unused Docker resources to free disk space:

docker system df

This shows disk usage by containers, images, and volumes. Remove unused resources:

docker container prune
docker image prune
docker volume prune

Monitoring Docker Logs

Monitor Docker daemon logs for warnings and errors:

sudo journalctl -u docker -f

The -f flag follows the log in real-time, useful for monitoring during operations.

Advanced Installation: Multi-Host Setup

Preparing Multiple Servers

For production environments with multiple servers, prepare each server identically:

#!/bin/bash
set -e

# Update system
sudo apt update
sudo apt upgrade -y

# Install prerequisites
sudo apt install -y ca-certificates curl gnupg lsb-release apt-transport-https software-properties-common

# Add Docker GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

# Add Docker repository
echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# Install Docker
sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# Start Docker
sudo systemctl start docker
sudo systemctl enable docker

# Configure daemon
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json > /dev/null <<'DAEMON'
{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  },
  "storage-driver": "overlay2"
}
DAEMON

sudo systemctl restart docker

# Add current user to docker group
sudo usermod -aG docker $USER

echo "Docker installation completed successfully"

Save this script as install-docker.sh, make it executable, and run it on each server:

chmod +x install-docker.sh
./install-docker.sh

Conclusion

You have successfully learned how to install Docker on Ubuntu 24.04 through comprehensive step-by-step instructions. Whether you chose the repository method for production environments or the convenience script for quick testing, Docker is now properly installed and configured on your system. You can verify installation by running containers, managing images, and utilizing the full power of containerization technology for your applications.

This installation represents the foundation of containerized application development and deployment. As you progress through your containerization journey, you will leverage this installed Docker instance to build custom images, orchestrate multi-container applications with Docker Compose, and implement container-based microservices architectures.

This article is part of the comprehensive Docker Complete Course available on learnwithirfan.com, your premier IT services provider in Riyadh, Saudi Arabia. Continue exploring the course to master Docker networking, storage, security, and advanced deployment strategies for enterprise-grade containerized infrastructure.

Final Thoughts

Installing Docker on Ubuntu 24.04 Step-by-Step is worth reviewing with a practical lens: understand the risk or opportunity, map it to your environment, and take clear next steps instead of reacting to headlines.

FAQ: Installing Docker on Ubuntu 24.04 Step-by-Step

What is Docker and Why Use It?+

Docker is a containerization platform that allows you to package applications with their dependencies into lightweight, portable containers. A container is essentially a standalone package that includes everything needed to run an application: code, runtime, system tools, libraries, and settings.

What are the benefits of Ubuntu 24.04 LTS?+

Ubuntu 24.04 LTS (Long Term Support) is the latest long-term support version, offering five years of standard support and additional extended security maintenance. This version includes improved package management, updated kernel versions, and better hardware support.

What are the requirements for System Docker Installation?+

Before installing Docker on Ubuntu 24.04, ensure your system meets the following requirements: To verify your system supports virtualization, run the following command: If this command returns output containing "vmx" (Intel) or "svm" (AMD), your processor supports virtualization.

What should you know about Updating the System?+

The first critical step is updating your Ubuntu system to the latest package versions. This ensures you have the latest security patches and compatibility fixes.

What should you know about Installing Prerequisites and Dependencies?+

Docker requires certain packages to function properly. Install the necessary dependencies.

Need help with infrastructure or security?

Work directly with Muhammad Irfan Aslam for Linux, cybersecurity, cloud, Docker, DevOps, CI/CD, or infrastructure support.

Hire Me for Support