Short answer
On Ubuntu 26.04 or 24.04, add Docker’s apt repository with its signing key, then run sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin. Docker starts at once and at every boot. Check it with sudo docker run hello-world. Then publish container ports on 127.0.0.1: a port published on all addresses skips the ufw firewall.
Tested on Ubuntu 26.04 and 24.04, two separate runs. On 24.04, every step is the same. Everything that differed
Before you start
- An Ubuntu 26.04 or 24.04 server and a user with sudo rights (create a sudo user). The test server had the firewall from the ufw article on, with only SSH open.
- This page installs Docker Engine, the server version. Docker Desktop is a different product for laptops with a graphical desktop and is not needed on a server.
- The images and containers you run later need disk space. The install itself took 389 MB.
Step 1: Remove anything that would get in the way
Ubuntu’s own Docker packages (docker.io and friends) clash with Docker’s. This removes any that are installed, and does nothing when there are none:
$ sudo apt remove $(dpkg --get-selections docker.io docker-compose docker-compose-v2 docker-doc podman-docker containerd runc | cut -f1)dpkg: no packages found matching docker.iodpkg: no packages found matching docker-composedpkg: no packages found matching docker-compose-v2dpkg: no packages found matching docker-docdpkg: no packages found matching podman-dockerdpkg: no packages found matching containerddpkg: no packages found matching runcSummary: Upgrading: 0, Installing: 0, Removing: 0, Not Upgrading: 0On a fresh server each “no packages found” line is good news, and apt removes nothing. If you ran containers with an old install, their images stay in /var/lib/docker and the new install uses them.
Step 2: Add Docker’s apt repository
Make sure the tools for downloading over HTTPS are there. On both test servers apt upgraded curl and ca-certificates (the list of certificate authorities HTTPS trusts), because the cloud image was a few weeks older than its updates:
$ sudo apt update[… 44 lines not shown …]Get:45 https://mirror.hetzner.com/ubuntu/security resolute-security/multiverse Translation-en [3,728 B]Get:46 https://mirror.hetzner.com/ubuntu/security resolute-security/multiverse amd64 c-n-f Metadata [120 B]Fetched 30.1 MB in 3s (11.5 MB/s)159 packages can be upgraded. Run 'apt list --upgradable' to see them.$ sudo apt install -y ca-certificates curlUpgrading: ca-certificates curl libcurl3t64-gnutls libcurl4t64 Summary: Upgrading: 4, Installing: 0, Removing: 0, Not Upgrading: 155 Download size: 1,262 kB Space needed: 15.4 kB / 36.5 GB available Get:1 https://mirror.hetzner.com/ubuntu/packages resolute-updates/main amd64 ca-certificates all 20260816ubuntu0.26.04.2 [138 kB]Get:2 https://mirror.hetzner.com/ubuntu/packages resolute-updates/main amd64 curl amd64 8.18.0-1ubuntu2.8 [273 kB]Get:3 https://mirror.hetzner.com/ubuntu/packages resolute-updates/main amd64 libcurl4t64 amd64 8.18.0-1ubuntu2.8 [430 kB]Get:4 https://mirror.hetzner.com/ubuntu/packages resolute-updates/main amd64 libcurl3t64-gnutls amd64 8.18.0-1ubuntu2.8 [421 kB]Fetched 1,262 kB in 1s (2,279 kB/s)Preconfiguring packages ... (Reading database… 52119 files and directories currently installed.)Preparing to unpack …/ca-certificates_20260816ubuntu0.26.04.2_all.deb…Unpacking ca-certificates (20260816ubuntu0.26.04.2) over (20260601~26.04.1)…Preparing to unpack …/curl_8.18.0-1ubuntu2.8_amd64.deb…Unpacking curl (8.18.0-1ubuntu2.8) over (8.18.0-1ubuntu2.4)…Preparing to unpack …/libcurl4t64_8.18.0-1ubuntu2.8_amd64.deb…Unpacking libcurl4t64:amd64 (8.18.0-1ubuntu2.8) over (8.18.0-1ubuntu2.4)…Preparing to unpack …/libcurl3t64-gnutls_8.18.0-1ubuntu2.8_amd64.deb…Unpacking libcurl3t64-gnutls:amd64 (8.18.0-1ubuntu2.8) over (8.18.0-1ubuntu2.4)…Setting up libcurl4t64:amd64 (8.18.0-1ubuntu2.8)…Setting up libcurl3t64-gnutls:amd64 (8.18.0-1ubuntu2.8)…Setting up ca-certificates (20260816ubuntu0.26.04.2)…Updating certificates in /etc/ssl/certs...rehash: warning: skipping ca-certificates.crt, it does not contain exactly one certificate or CRL4 added, 5 removed; done.Running hooks in /etc/ca-certificates/update.d...done.Setting up curl (8.18.0-1ubuntu2.8)…Processing triggers for man-db (2.13.1-1build1)…Processing triggers for libc-bin (2.43-2ubuntu2.3)… Scanning processes...Scanning candidates...Scanning linux images... Running kernel seems to be up-to-date. Restarting services... systemctl restart packagekit.service No containers need to be restarted. No user sessions are running outdated binaries. No VM guests are running outdated hypervisor (qemu) binaries on this host.$ apt-cache policy docker-ce docker.iodocker-ce: Installed: (none) Candidate: 5:29.10.0-1~ubuntu.26.04~resolute Version table: 5:29.10.0-1~ubuntu.26.04~resolute 500 500 https://download.docker.com/linux/ubuntu resolute/stable amd64 Packages 5:29.9.3-1~ubuntu.26.04~resolute 500 500 https://download.docker.com/linux/ubuntu resolute/stable amd64 Packages[… 53 lines not shown …]On the day of the test Docker’s repository offered 29.10.0 and Ubuntu’s offered 29.1.3, on both releases. Both work. This page uses Docker’s because it gets every Docker release a few days after it is out, and it comes with the current Compose and Buildx plugins. Ubuntu’s moves only with Ubuntu’s own updates. Pick one and never mix them: step 1 is there because the two clash.
Step 3: Install Docker Engine
$ sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-pluginInstalling: containerd.io docker-buildx-plugin docker-ce docker-ce-cli docker-compose-plugin Installing dependencies: docker-ce-rootless-extras pigz Suggested packages: cgroupfs-mount | cgroup-lite docker-model-plugin Summary: Upgrading: 0, Installing: 7, Removing: 0, Not Upgrading: 155[… 58 lines not shown …]docker-ceis the engine, the background service that runs containers.docker-ce-cliis thedockercommand you type.containerd.iois the lower layer that starts and stops containers for the engine.docker-buildx-pluginbuilds images (docker build), anddocker-compose-plugingives youdocker compose, for apps with several containers.
The install enables two systemd units, docker.service and docker.socket, so Docker starts again after every reboot. There is nothing to start by hand.
Step 4: Check that it works
$ systemctl status docker --no-pager -n 0● docker.service - Docker Application Container Engine Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; preset: enabled) Active: active (running) since Wed 2026-11-18 22:50:46 UTC; 7s ago Invocation: 008f0fd9a1b545ffa7cad45f5dbda730TriggeredBy: ● docker.socket Docs: https://docs.docker.com Main PID: 8547 (dockerd) Tasks: 9 Memory: 29.6M (peak: 29.7M) CPU: 459ms CGroup: /system.slice/docker.service └─8547 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock“enabled” and “active (running)”. docker version asks both halves, the command and the engine, for their versions. Only a working engine answers the Server part:
$ sudo docker versionClient: Docker Engine - Community Version: 29.10.0 API version: 1.57 Go version: go1.27.4 Git commit: fdd4b8e Built: Mon Nov 16 11:01:05 2026 OS/Arch: linux/amd64 Context: default Server: Docker Engine - Community Engine: Version: 29.10.0 API version: 1.57 (minimum version 1.40) Go version: go1.27.4 Git commit: 06db173 Built: Mon Nov 16 11:01:32 2026 OS/Arch: linux/amd64 Experimental: false containerd: Version: v2.4.2 GitCommit: b7a25261e029d68978bbf290df0a62fc819b3c51 runc: Version: 1.5.3 GitCommit: v1.5.3-0-g46365c62 docker-init: Version: 0.19.0 GitCommit: de40ad0Now run a real container. hello-world downloads a tiny image from Docker Hub, runs it, and it prints a message:
$ sudo docker run hello-worldUnable to find image 'hello-world:latest' locallylatest: Pulling from library/hello-world 4f55086f7dd0: Pull completeDigest: sha256:1e4c05b897a751332ce85c7e9449da2d93514ea2dea6dbb0e2753c9e949b2bfaStatus: 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. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/The download, the container and the output all worked. Compose came with the install as a plugin, so it is docker compose with a space. The old separate docker-compose program is not needed:
$ docker compose versionDocker Compose version v5.8.0Running docker without sudo
Every command above used sudo. Without it, your user is refused:
$ docker pspermission denied while trying to connect to the docker API at unix:///var/run/docker.sockDocker 29 words the error this way. Older releases said “the Docker daemon socket”, but it is the same problem. The fix is the docker group, but that group is as powerful as root. Fix “permission denied” on docker.sock shows how, why it does not work until you log in again, and what to avoid.
Docker skips ufw: published ports are open to everyone
This catches most people who run Docker behind ufw. The test server’s firewall allowed only SSH:
$ sudo ufw statusStatus: active To Action From-- ------ ----OpenSSH ALLOW AnywhereOpenSSH (v6) ALLOW Anywhere (v6)Start a web server in a container and publish its port 80 on the server’s port 8080, as most guides show it:
$ sudo docker run -d --name web -p 8080:80 nginx:alpine[… 12 lines not shown …]Digest: sha256:0563c36f94a6d3ec3584161b77859f740f7e20b4853f52c796a864ce6908e8eaStatus: Downloaded newer image for nginx:alpine143890d64f521b09baa80ea60974fb812b8959730008d13312cacfe98e5ae048Then ask for the page from another machine, here a second computer at 192.0.2.2. -w prints only the HTTP status code:
$ curl -sS -m 5 -o /dev/null -w '%{http_code}\n' http://203.0.113.10:8080200200: the page is served, although ufw has no rule for port 8080. Docker writes its own firewall rules, and they act before ufw’s. A packet for port 8080 is redirected to the container in the nat table and never passes ufw’s input rules. You can see the rule:
$ sudo iptables -t nat -S DOCKER | grep 8080-A DOCKER ! -i docker0 -p tcp -m tcp --dport 8080 -j DNAT --to-destination 172.17.0.2:80172.17.0.2 is the container’s address on Docker’s internal network. Any packet for port 8080 on the server goes there, whatever address it came from.
The fix: put an address in front of the port. 127.0.0.1:8080:80 publishes the port on the server itself only. Nginx on the same server can still pass visitors to it, which is how a site normally runs: Nginx on 80 and 443 with HTTPS, the container behind it. Replace the container:
$ sudo docker rm -f web$ sudo docker run -d --name web -p 127.0.0.1:8080:80 nginx:alpineweb0af39ecf539a37e72acd50b58bab77cbf27e519f9dca6bcc520ee13b44b01724$ curl -sS -m 5 -o /dev/null -w '%{http_code}\n' http://203.0.113.10:8080curl: (28) Connection timed out after 5002 milliseconds000No answer from outside. The packet now reaches ufw’s rules, and ufw drops it. On the server itself the container still answers:
$ curl -sS -o /dev/null -w '%{http_code}\n' http://127.0.0.1:8080200$ sudo docker ps --format "{{.Names}} {{.Ports}}"web 127.0.0.1:8080->80/tcpIn a Compose file it is the same: write ports: ["127.0.0.1:8080:80"], not "8080:80". When a port really must be public, publish it on purpose and remember that ufw has no say over it.
What these steps changed on the server
Both runs recorded the server before the first step and after the last (see the Tested on box below). Docker’s repository added five packages (Docker Engine, its command-line client, containerd, Buildx and Compose), and apt upgraded four others: curl, ca-certificates and two libcurl libraries. docker.service was enabled. The disk holds about 740 MB more on 26.04 and 800 MB on 24.04, most of it the Docker packages and the images pulled for the tests.
A scan of the 1,000 most common TCP ports from a second server found only SSH (22) open before and after. Installing Docker opens no port by itself: the hole on this page appears only when you publish a port. No Lynis score is shown: the check does not record one for this page.
Ubuntu 26.04 vs 24.04: what changed
The same check ran on a fresh 26.04 server and on a fresh 24.04 server, each with its own run log. Docker itself behaved the same on both, the firewall hole included. What differed is Ubuntu around it:
| What | Ubuntu 26.04 | Ubuntu 24.04 |
|---|---|---|
| System | Ubuntu 26.04.1 LTS7.0.0-30-generic | Ubuntu 24.04.4 LTS6.8.0-138-generic |
| docker-ce | 5:29.10.0-1~ubuntu.26.04~resolute | 5:29.10.0-1~ubuntu.24.04~noble |
| docker-ce-cli | 5:29.10.0-1~ubuntu.26.04~resolute | 5:29.10.0-1~ubuntu.24.04~noble |
| containerd.io | 2.4.2-4~ubuntu.26.04~resolute | 2.4.2-4~ubuntu.24.04~noble |
| docker-buildx-plugin | 0.39.0-1~ubuntu.26.04~resolute | 0.39.0-1~ubuntu.24.04~noble |
| docker-compose-plugin | 5.8.0-1~ubuntu.26.04~resolute | 5.8.0-1~ubuntu.24.04~noble |
| ufw | 0.36.2-9build1 | 0.36.2-6 |
| apt’s output | apt 3: a “Summary:” block (“Upgrading: 0, Installing: 7, …”) with the disk space free | the older one-line “0 upgraded, 7 newly installed, …” |
sudo apt update | ends at the package count, no “Reading package lists… Done” | ends with “Reading package lists… Done” and two more such lines |
| curl and ca-certificates (step 2) | apt upgrades curl, ca-certificates and two libcurl packages | the same four packages are upgraded |
systemctl status docker | an extra Invocation: line (newer systemd) | no Invocation: line |
| Docker’s repository suite | resolute | noble |
| Ubuntu’s own docker.io | 29.1.3-0ubuntu4.1 (Docker’s repository: 29.10.0) | 29.1.3-0ubuntu3~24.04.2 (Docker’s repository: 29.10.0) |
| Published port skips ufw | yes: 200 from outside; fixed with 127.0.0.1: | yes: 200 from outside; fixed with 127.0.0.1: |
| Proof | Run log, 30 checks passed | Run log, 30 checks passed |
Undo: remove Docker completely
$ sudo apt purge -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras[… 12 lines not shown …] (Reading database… 52354 files and directories currently installed.)Removing docker-ce (5:29.10.0-1~ubuntu.26.04~resolute)…Removing containerd.io (2.4.2-4~ubuntu.26.04~resolute)…Removing docker-buildx-plugin (0.39.0-1~ubuntu.26.04~resolute)…Removing docker-ce-cli (5:29.10.0-1~ubuntu.26.04~resolute)…Removing docker-ce-rootless-extras (5:29.10.0-1~ubuntu.26.04~resolute)…Removing docker-compose-plugin (5.8.0-1~ubuntu.26.04~resolute)…Processing triggers for man-db (2.13.1-1build1)…(Reading database… 52129 files and directories currently installed.)Purging configuration files for docker-ce (5:29.10.0-1~ubuntu.26.04~resolute)…Purging configuration files for containerd.io (2.4.2-4~ubuntu.26.04~resolute)…Purging the packages leaves the data behind on purpose:
$ sudo du -sh /var/lib/docker /var/lib/containerd272K /var/lib/docker91M /var/lib/containerdDelete it, with the repository and the key from step 2:
$ sudo rm -rf /var/lib/docker /var/lib/containerd && sudo rm /etc/apt/sources.list.d/docker.sources /etc/apt/keyrings/docker.asc$ command -v docker || echo "docker: not installed"docker: not installed