Website Vidya
DeploymentStep-by-Step Guide

How to Install Docker on Ubuntu 24.04

Learn how to install docker on ubuntu 24.04 with official Docker CE repositories, non-root user permissions, Docker Compose plugin, and testing.

RR
Rajesh RayLead Systems Educator
Published:
5 min read
PDF Cheat Sheet
How to Install Docker on Ubuntu 24.04
AI Executive SummaryCORE CIS AI

5 min read

Learn how to install docker on ubuntu 24.04 with official Docker CE repositories, non-root user permissions, Docker Compose plugin, and testing.

Key Highlights
  • Prerequisites and Supported Releases
  • Step 1: Removing Conflicting Unofficial Packages
  • Step 2: Adding the Official Docker APT Repository
Grounded in full engineering runbookCORE CIS Ai Engine

Containerization has transformed the modern software development and cloud operations landscape, allowing software engineers to bundle applications with all libraries and dependencies into lightweight, immutable container images.

Docker is the world's most widely adopted containerization platform, providing developers with consistent runtime environments that eliminate the notorious 'it works on my machine' dilemma.

While Ubuntu includes a generic docker.io package in standard repositories, installing the official Docker Community Edition (Docker CE) directly from Docker's official upstream repository ensures you receive the latest container engine features, security patches, and the unified docker compose plugin.

In this tutorial, we walk through how to install docker on ubuntu step-by-step, configure non-root user execution, and launch a test container.

Advertisement

Prerequisites and Supported Releases

This guide is thoroughly verified on Ubuntu 24.04 LTS (Noble Numbat) & Ubuntu 22.04 LTS. The instructions apply cleanly to cloud instances (AWS EC2, Google Compute Engine, DigitalOcean, Hetzner), bare-metal servers, and local virtual machines.

Before proceeding, ensure you have the following requirements satisfied:

  • A server or computer running Ubuntu 24.04 LTS or Ubuntu 22.04 LTS.
  • A non-root user account with sudo administrative privileges.
  • A 64-bit hardware architecture (x86_64, arm64, or armhf).
  • Access to a bash terminal shell.

Step 1: Removing Conflicting Unofficial Packages

Before installing official Docker Community Edition, ensure any unofficial or legacy container packages are removed from your system to avoid binary conflicts.

Run the following command to clean up potential conflicting packages:

Advertisement

If none of these packages are installed, APT simply reports that no packages were removed:

# Remove legacy or unofficial container packages:
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do \
  sudo apt remove -y $pkg; \
done

Step 2: Adding the Official Docker APT Repository

Install prerequisite utilities, import Docker's official GPG key into /etc/apt/keyrings/, and add the repository source file.

This ensures all downloaded Docker packages are verified cryptographically using modern signed-by standards:

Execute these commands to configure the repository:

# Install repository transport utilities:
sudo apt update
sudo apt install -y ca-certificates curl

# Create keyrings directory:
sudo install -m 0755 -d /etc/apt/keyrings

# Download and dearmor official Docker GPG key:
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

# Add the official Docker repository to 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

# Refresh package index:
sudo apt update

Step 3: Installing Docker Engine and Docker Compose Plugin

Install the core Docker Engine, CLI interface, containerd runtime, and the modern Docker Compose v2 plugin:

Advertisement

Execute the installation command:

Verify that the Docker daemon starts automatically:

# Install Docker Community Edition packages:
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# Verify Docker daemon status:
sudo systemctl status docker
# Expected output confirms: Active: active (running)

# Verify installed versions:
docker --version
# Expected output: Docker version 26.x or newer
docker compose version
# Expected output: Docker Compose version v2.x

Step 4: Managing Docker as a Non-Root User

By default, the Docker daemon binds to a UNIX domain socket owned by the root user, requiring sudo for every command.

To execute docker commands without prepending sudo, add your active user account to the docker supplementary group:

Apply group changes using newgrp or log out and log back in:

# Add active user to the docker group:
sudo usermod -aG docker $USER

# Activate group changes in current shell session without logging out:
newgrp docker

# Test running docker without sudo:
docker ps
# Output confirms empty table without permission denied errors.

Step 5: Verifying Installation with hello-world Container

Verify that Docker downloads images from Docker Hub, initializes container namespaces, and executes workloads properly by running the official hello-world container:

Execute the run command in your terminal:

# Run the diagnostic test container:
docker run hello-world

# Expected output confirmation snippet:
# Hello from Docker!
# This message shows that your installation appears to be working correctly.
#
# To generate this message, Docker took the following steps:
#  1. The Docker client contacted the Docker daemon.
#  2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
#  3. The Docker daemon created a new container from that image which runs the
#     executable that produces the output you are currently reading.
#  4. The Docker daemon streamed that output to the Docker client.

Step 6: Configuring Daemon Live-Restore and Production Logging

In production environments, Docker daemon upgrades or service restarts should not terminate running containers.

Enabling the live-restore feature in /etc/docker/daemon.json keeps active containers running uninterrupted during Docker engine maintenance.

Additionally, configuring JSON log rotation prevents container stdout/stderr log files from consuming host disk space uncontrollably:

Create or edit /etc/docker/daemon.json and apply the configuration with a daemon reload:

{
  "live-restore": true,
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "20m",
    "max-file": "3"
  }
}

Applying Daemon Configuration

Reload systemd and restart the Docker service to apply the production logging and live-restore policies:

Verify that the Docker daemon loaded the parameters successfully:

# Reload systemd and restart Docker daemon:
sudo systemctl daemon-reload
sudo systemctl restart docker

# Verify live-restore status:
docker info | grep -i "live restore"
# Output confirms: Live Restore Enabled: true

Troubleshooting and Common Errors

When configuring Ubuntu servers, unexpected permission errors, network timeouts, or lock contention can occur. Review these common issues and verified resolutions:

permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock

Cause: The user is not a member of the docker group, or group membership has not refreshed.

Resolution: Run sudo usermod -aG docker $USER and log out/log in or execute newgrp docker.

sudo usermod -aG docker $USER && newgrp docker

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?

Cause: The docker systemd service is stopped.

Resolution: Start the service with sudo systemctl start docker and check logs with journalctl -u docker.

sudo systemctl start docker

Package docker-ce has no installation candidate

Cause: The Docker repository file in /etc/apt/sources.list.d/docker.list contains an invalid Ubuntu version codename.

Resolution: Ensure $(. /etc/os-release && echo "$VERSION_CODENAME") resolves to noble or jammy and run sudo apt update.

cat /etc/apt/sources.list.d/docker.list

Security Best Practices and Hardening

Granting a user membership in the docker group provides root-equivalent privileges on the host system; only grant this to trusted administrative users.

Configure Docker daemon live-restore in /etc/docker/daemon.json ({"live-restore": true}) so containers continue running during daemon updates.

Regularly prune dangling unused images and stopped containers using docker system prune -a.

Deepen your Linux system administration skills with our related production-tested guides:

Authoritative References and Official Documentation

Frequently Asked Questions

Quick answers to common questions and configurations

4 FAQs
docker.io is Canonical's downstream repackaging of Docker, which may lag behind upstream releases. docker-ce (Community Edition) is maintained directly by Docker Inc., providing immediate access to the latest engine releases, buildx, and compose plugins.
Because you installed Docker via the official APT repository, standard system update commands (sudo apt update && sudo apt upgrade) automatically update Docker Engine and its plugins.
docker-compose (with a hyphen) was the legacy Python-based Compose v1 tool, which is now deprecated. docker compose (with a space) is the modern Compose v2 plugin written in Go and integrated directly into the Docker CLI.
Run sudo apt purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin and remove storage directories with sudo rm -rf /var/lib/docker /var/lib/containerd.
RR
Written byVerified Author

Rajesh Ray

I’m Rajesh Rai, a full-stack developer, Linux administrator, and technology enthusiast passionate about making complex technology easier to understand and use.

SPAM-FREE MODERATED DISCOURSE

Join the Conversation & Perspective

Have thoughts, counterpoints, or reflections on this story? Engage directly with fellow readers and editorial contributors.

AT
MP
JV
+2

No comments on this guide yet. Be the first to share your thoughts or ask a question!

Recommended Reading10 Guides

Related Technical Guides

Tested runbooks, server administration walkthroughs, and troubleshooting guides

Uncategorized•

How to Redirect HTTP to HTTPS in Nginx

If you’re running a website today and it’s still accessible over plain HTTP, you’re already behind. Modern browsers flag non-HTTPS sites as “Not Secure,” search engines favor encrypted websites, and users are far more cautious about where t...

RR
Rajesh Rai
Read More
Featured Infrastructure PartnerUp to 75% OFF + 3 Months Free

Supercharge Your Linux & Cloud Workloads with Hostinger

Deploy high-speed NVMe KVM VPS, Docker containers, and LiteSpeed-accelerated WordPress servers in under 60 seconds with full root access, dedicated IPv4, and 24/7 technical support.

Pure NVMe SSD StorageFull Root Access & SSHFree Domain & Unlimited SSL99.9% Uptime SLA
Plans from$2.99/mo
Claim Hostinger DealAffiliate link • Special discount applied at checkout