How to Install Docker on Ubuntu 24.04

Ulrik Christensen

September 17, 2025

You want to get started with containers. But where to start? The first thing you want to do is to learn everything there is to know about Docker. This article will show you how to get started with Docker on Ubuntu Linux.

For this tutorial, you need a freshly installed Ubuntu 24.04 server.

Why Ubuntu Linux and not Windows?


Let’s first go over why we are running Docker on Linux instead of Windows. Linux is generally the better choice because Docker was initially built around Linux kernel features, such as cgroups, namespaces, and union filesystems, meaning containers run natively without extra overhead. On Windows, Docker relies on a virtual machine (through WSL2 or Hyper-V) to provide a Linux kernel, which introduces additional complexity, increased resource usage, and slower performance. Linux also offers broader compatibility with container images and orchestration tools like Kubernetes, since most container workloads are developed and tested against Linux environments. In short, running Docker on Linux is faster, more efficient, and aligns better with how containers are designed to work.

Let’s get started with the installation of Docker on Ubuntu Linux

The first thing you need to do is to uninstall any conflicting packages. If you are using a freshly installed Ubuntu machine, the chances of any conflicting packages are very low. But run the command below anyway to be on the safe side.

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

Before installing Docker Engine on a new host for the first time, you must configure the Docker apt repository. Once the repository is set up, you can use it to install Docker and keep it up to date with future updates. Use the commands below.

# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
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 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 "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

Now you are ready to install all the packages. Use the command below to begin the installation of Docker.

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

Manage Docker as a non-root user

By default, you need to preface the Docker command with sudo. To avoid that, you can add your user to the Docker group by using the command below. This is not recommended for use in a production environment.

sudo gpasswd -a $USER docker

Now Docker is installed. You can test your installation by typing the command’ docker’. If you want to try to run a container, you can try the Nginx container by using the command below.

docker run --name some-nginx -d -p 8080:80 nginx

Once it is up and running, type http://IP_OF_YOUR_MACHINE:8080 into your browser, and you will see that Nginx is running.

Install and use Docker Compose

Docker Compose lets you define and run multi-container applications from a single YAML file, so you no longer have to type long docker run commands. Compose v2 is already installed, because you included the docker-compose-plugin package in the installation above. It is used with the docker compose command (with a space). Verify the installation with the command below.

docker compose version

If the plugin is missing, for example on a machine where Docker was installed earlier without it, you can install it from the Docker apt repository you configured above.

sudo apt-get update
sudo apt-get install docker-compose-plugin -y

Create your first Compose project

Create a folder for the project and a file called compose.yaml.

mkdir ~/compose-demo && cd ~/compose-demo
nano compose.yaml

Paste the following into the file. It defines a single service called web that runs the official Nginx image and publishes it on port 8081, so it does not clash with the Nginx container you started earlier on port 8080.

services:
  web:
    image: nginx:latest
    ports:
      - "8081:80"
    restart: unless-stopped

Save the file and start the project in the background.

docker compose up -d

Check that the service is running and follow its logs (press Ctrl+C to stop following the logs).

docker compose ps
docker compose logs -f web

Open http://IP_OF_YOUR_MACHINE:8081 in your browser, and you will see the Nginx welcome page. When you are done, stop and remove the containers and network that Compose created by running the command below from the same folder.

docker compose down

Find more container images and descriptions on how to use them on https://hub.docker.com/