Skip to content

ContainerFor beginnersDuration around 10 min.

How to install Docker on Ubuntu: Docker Engine and Compose

By the end of this tutorial, Docker Engine from the official Docker repository will be running on your Ubuntu server, along with the Compose plugin and a first service. You need a server with Ubuntu 24.04 LTS or 26.04 LTS and a user with sudo privileges.

Tested on with Ubuntu 24.04 LTS and Ubuntu 26.04 LTS

At a glance

  • Docker comes from Docker's own repository, not from the Ubuntu package docker.io โ€” this ensures you get the latest version and the Compose plugin.
  • After installation, the hello-world container checks if everything is running; a Compose example starts a web server on port 8080.
  • Published container ports bypass ufw rules. Bind anything that should only be reached by a reverse proxy to 127.0.0.1.

Prerequisites

  • A server with Ubuntu 24.04 LTS or Ubuntu 26.04 LTS in the 64-bit version (amd64 or arm64). Docker also officially supports Ubuntu 22.04 LTS; derivatives like Linux Mint, however, are not supported.
  • A user with sudo privileges and an SSH connection to the server. On a VPS or a Cloud Server from ENTRONYX CLOUD, you sign in with your SSH key.
  • Around 2 GB of memory is enough for the first containers; you only need more depending on what you run inside them.

If you do not want to set up Docker manually: in the VPS configurator, you can select โ€œDocker CE + Composeโ€ on Ubuntu 24.04 LTS as an application. This tutorial shows what happens during that process.

Step 1: remove third-party Docker packages

Ubuntu includes its own packages such as docker.io or podman-docker. They conflict with Docker's packages. The command only removes what is installed; on a fresh server, it will report that there is nothing to do.

Remove conflicting packages
sudo apt remove $(dpkg --get-selections docker.io docker-compose docker-compose-v2 docker-doc docker-buildx podman-docker containerd runc | cut -f1)

Images, containers and volumes under /var/lib/docker remain untouched.

Step 2: set up the Docker repository

First, you download the Docker signature key, then you add the repository. The expression in line Suites inserts the codename of your Ubuntu version โ€” noble for 24.04, resolute for 26.04 โ€”, and line Architectures inserts the server's architecture.

Key and repository
sudo apt update
sudo apt install -y 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
 
sudo tee /etc/apt/sources.list.d/docker.sources <<EOF
Types: deb
URIs: https://download.docker.com/linux/ubuntu
Suites: $(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}")
Components: stable
Architectures: $(dpkg --print-architecture)
Signed-By: /etc/apt/keyrings/docker.asc
EOF
 
sudo apt update

The last line reads the new repository. Its output contains a line with download.docker.com; if it is missing, the file at /etc/apt/sources.list.d/docker.sources is incorrect.

Step 3: install Docker Engine and Compose

This installs the Engine, the command-line tool, containerd, and the plugins for Buildx and Compose.

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

The service starts automatically after installation and again on the next reboot. The following two commands show whether it is running and whether a container starts.

Check the service and first container
sudo systemctl status docker
sudo docker run hello-world
Output of hello-world (excerpt)
Hello from Docker!
This message shows that your installation appears to be working correctly.

Which versions are now installed:

Show versions
docker --version
docker compose version

Step 4: use Docker without sudo

By default, every Docker command requires sudo. Add your user to the docker group; the installation created it. The membership only takes effect after a new login โ€” newgrp docker opens it immediately in the current session.

Add user to the docker group
sudo usermod -aG docker $USER
newgrp docker
docker run hello-world

The docker group is as powerful as root

Anyone who can start containers can mount and modify the server's file system. Only add accounts to the group that you would also trust with root access.

Step 5: start the first service with Docker Compose

Compose describes services in a file. Create a folder and inside it the file compose.yaml with this content:

~/compose-test/compose.yaml
services:
  web:
    image: nginx:stable
    ports:
      - "8080:80"

Then you start the service in the background, view its status, request it, and stop it again. The response from curl begins with HTTP/1.1 200 OK.

Start, check, stop service
mkdir -p ~/compose-test && cd ~/compose-test
nano compose.yaml
docker compose up -d
docker compose ps
curl -I http://localhost:8080
docker compose down

Step 6: set ports and firewall correctly

A port you publish with ports is accessible from the outside โ€” even if ufw blocks it. Docker routes the packets past the ufw rules. If a service should only be accessible via a reverse proxy on the same server, bind the port to the address 127.0.0.1:

compose.yaml (excerpt)
    ports:
      - "127.0.0.1:8080:80"

The Nginx as a reverse proxy guide shows how to set up a reverse proxy with HTTPS in front of it.

Update Docker

Because Docker now comes from a package repository, you update it with the rest of the system. An update restarts the service; containers with a restart rule like restart: unless-stopped will start up again afterwards.

Update system and Docker
sudo apt update
sudo apt upgrade

Typical errors

  • โ€œpermission denied while trying to connect to the Docker daemon socketโ€: The docker group is not yet effective. Sign in again or use newgrp docker.
  • โ€œCannot connect to the Docker daemon โ€ฆ Is the docker daemon running?โ€: The service is not running. Start it with sudo systemctl start docker and read the reason with sudo journalctl -u docker.
  • Package conflicts during installation: A package from step 1 is still installed. Repeat the removal command.
  • Container is accessible from the outside even though ufw blocks the port: This is the behaviour from step 6 โ€” bind the port to 127.0.0.1.

We tested all commands in this guide on 2 December 2026 โ€” with Ubuntu 24.04 LTS and Ubuntu 26.04 LTS. If a step changes at the manufacturer, we update it here along with the date.

Official documentation

Frequently asked questions about Docker on Ubuntu

What is the difference between docker.io and docker-ce?

docker.io is the package that Ubuntu builds and maintains itself; docker-ce comes from the Docker package repository. The Docker repository delivers new versions earlier and includes the Compose plugin, which is why this guide uses it. Installing both packages at the same time leads to conflicts.

Do I also need the docker-compose program?

No. The Compose plugin replaces the previous standalone program; the commands are docker compose with a space instead of docker-compose with a hyphen. The compose.yaml file remains the same.

Does Docker also run on ARM servers?

Yes. The Docker package repository for Ubuntu contains packages for amd64, arm64, armhf, s390x and ppc64le. The expression in the package repository inserts the architecture of the server itself.

Can I also set up Docker using the Docker installation script?

Docker itself recommends the script only for test and development environments. On a server that runs for a longer time, the package repository is the better way: updates come with the rest of the system.

Why does ufw not block my container ports?

Docker sets its own rules that route incoming packets for published ports before ufw checks them. A service that should only be accessible internally is therefore bound to 127.0.0.1 instead of all addresses.

Which Ubuntu versions does Docker support?

The official Docker guide lists Ubuntu 22.04 LTS, 24.04 LTS, 26.04 LTS and 26.10, each in the 64-bit version. The guide on the Ubuntu version shows which version your server has.

Show Ubuntu version

Further reading

More tutorials

  • How to set up Nginx as a reverse proxy with HTTPS (Letโ€™s Encrypt)

    Web serverFor beginnersabout 20 min

    Following this tutorial, Nginx will accept requests to your domain, pass them to an application on the same server, and serve everything over HTTPS with a Letโ€™s Encrypt certificate. This is suitable for Node.js, Python, Go, or a container listening on a local port.

  • How to install WordPress on your own server: Nginx, PHP and MariaDB

    Web serverFor advanced usersabout 30 min

    This tutorial brings WordPress to your own server with Ubuntu: Nginx as the web server, PHP-FPM for WordPress, MariaDB as the database and a certificate from Letโ€™s Encrypt. Finally, you will complete the setup in the browser, where you create the title and administrator.

  • How to set up fail2ban: protect SSH on Ubuntu against password guessing

    SecurityFor beginnersabout 10 min

    fail2ban monitors the login attempts on your server and bans addresses that try an incorrect password too often. Following this guide, it protects SSH access with custom values for ban duration and failed attempts, and you will know how to check and lift a ban.

A server for your containers

On VPS, you work with root access via SSH and choose Ubuntu 24.04 LTS or 26.04 LTS as the image โ€” the commands in this guide will run there unchanged.