Docker Installation on Ubuntu

Posted on September 7, 2023 (Last modified on November 8, 2025) • 6 min read • 1,074 words

Everything starts with Docker - complete installation guide for Ubuntu Server with verification steps

Docker Installation on Ubuntu
Photo by frank mckenna  on Unsplash 

Today we’re diving into the absolute foundation for modern homelab and server projects: Docker. Whether you want to run containers for web services, databases, monitoring tools, or entire development environments – everything starts with a clean Docker installation.

This article is intentionally brief and focused, because Docker installation is relatively straightforward. I’m following the official Docker documentation here, supplemented with some practical verification steps. Think of this post as the cornerstone for upcoming projects – the really exciting stuff comes after this!

Prerequisites

Before we get started, make sure you meet the following prerequisites:

  • An Ubuntu Server (20.04, 22.04, or 24.04 LTS)
  • Sudo privileges on the system
  • Basic Linux knowledge (command line, text editor)
  • Internet connection for downloading packages

Uninstall Old Docker Installations

Before we install Docker fresh, let’s clean up first. If your system already has an old or unofficial Docker installation, we should remove it. This prevents conflicts between different Docker versions.

Run the following command to uninstall all potentially existing Docker versions:

for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done

If none of these packages is installed, you’ll receive a corresponding message – that’s completely fine and means your system is “clean.”

Install using the apt Repository

Now we get to the core: installing Docker via the official apt repository. This method has the advantage that you always get the latest stable version of Docker and can conveniently apply updates via apt.

Repository Preparation

First, we update the package lists and install the necessary dependencies:

sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings

These packages are needed to securely add the Docker repository:

  • ca-certificates – Certificates for HTTPS connections
  • curl – For downloading the GPG key

Add GPG Key

Now we add Docker’s official GPG key. This ensures that the downloaded packages are authentic:

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

Set up Repository

Now we set up the official Docker repository:

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
sudo apt-get update

This command creates the file /etc/apt/sources.list.d/docker.list with the correct repository URL for your Ubuntu version.

Verify Repository

Before we install Docker, let’s verify that the repository is configured correctly and see which Docker version is available:

apt-cache policy docker-ce
docker-ce:
  Installed: (none)
  Candidate: 5:19.03.9~3-0~ubuntu-focal
  Version table:
     5:19.03.9~3-0~ubuntu-focal 500
        500 https://download.docker.com/linux/ubuntu focal/stable amd64 Packages

Perfect! The output shows:

  • Installed: (none) – Docker is not yet installed
  • Candidate: – The version that will be installed
  • The available versions from the Docker repository

Install Docker Engine

Now we can install Docker CE (Community Edition):

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

This command installs:

  • docker-ce – The Docker Engine (the heart of it all)
  • docker-ce-cli – The command-line tools
  • containerd.io – The container runtime
  • docker-buildx-plugin – Advanced build system
  • docker-compose-plugin – Docker Compose as a plugin (very handy!)

Start and Enable Docker Service

Docker should start automatically after installation. To be safe, let’s verify this and enable automatic start on system boot:

sudo systemctl status docker
● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2023-09-10 10:15:23 UTC; 2min ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 12345 (dockerd)
      Tasks: 8
     Memory: 28.5M
        CPU: 245ms
     CGroup: /system.slice/docker.service
             └─12345 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Great! The status shows active (running) – Docker is running. If the service is not active, start it manually:

sudo systemctl start docker

Make sure Docker starts automatically on system boot:

sudo systemctl enable docker

Functional Test

To wrap things up, let’s run a small functional test. Docker provides a special test image for this purpose:

sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete
Digest: sha256:4bd78111b6914a99dbc560e6a20eab57ff6655aea4a80c50b0c5491968cbc2e6
Status: Downloaded newer image for hello-world:latest

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.
    (amd64)
 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, which sent it
    to your terminal.

Optional: Use Docker Without sudo

By default, you need sudo to execute Docker commands. For production use on servers this is often desired, but for your local homelab server it can be annoying.

If you want to execute Docker commands without sudo, add your user to the docker group:

sudo usermod -aG docker $USER

Test whether it works:

docker run hello-world

If you can execute this command without sudo – congratulations, everything is perfectly set up!

Conclusion

With Docker, you can now:

  • Download and start containers from Docker Hub
  • Create your own images
  • Orchestrate multi-container applications with Docker Compose
  • Containerize your entire homelab infrastructure

Everything starts with Docker – and you’ve just mastered that beginning.

In upcoming articles, we’ll explore Docker Compose, set up practical containers for your homelab (reverse proxy, monitoring, dashboards), and dive into advanced topics like networks and volumes.

Have fun experimenting with Docker!

Further Reading: