How to Install Docker on Ubuntu Server: Step-by-Step
Part of New VPS setup, our guide to this topic
To install Docker on Ubuntu 24.04, add Docker’s official apt repository, then install the docker-ce package with apt. Add your user to the docker group so you can run containers without sudo, and confirm the install with docker run hello-world.
On this page
This guide has no affiliate links in the steps.
Docker is the step that turns a bare VPS into a machine that runs almost anything, one command at a time. If this is a fresh server, work through our new VPS setup checklist first — a sudo user, key login and a firewall come before any software you install. The steps below install Docker Engine, not Docker Desktop, and they end with the one Docker gotcha that catches most new self-hosters: published ports skip your firewall.

Before you start
You need three things:
- Ubuntu 24.04 LTS server with a sudo user you log in as. Docker’s install page also supports 22.04 and 26.04 LTS with the same commands; the release codename is filled in for you.
- A terminal on your own computer. The
dockercommands run on the server; you only needsshlocally. New to that? Read how to SSH into a VPS, and set up SSH key login before you put services on the box. - A stable network connection to
download.docker.com. If your provider or network blocks it, the key step fails.
This guide uses Docker’s official apt repository, not Ubuntu’s docker.io package. Docker’s documentation calls the distribution packages unofficial, says they can conflict with Docker’s own, and tells you to remove them first. The official repo also gives you the Buildx and Compose plugins in the same install.
Docker itself is light. The containers you run are what eat memory, so size the server for the workload, not for Docker. A 2 GB VPS comfortably runs Docker plus a few small containers; the table at the end lists the cheapest 2 GB plan at each provider we read daily.
In the commands, $USER is a shell variable that expands to your username, and noble is Ubuntu 24.04’s codename. Type the lines exactly as shown.
How to install Docker on Ubuntu: 7 steps
Update the system and remove conflicting packages
On the server, update the package index and install the two tools the repository step uses:
serversudo apt update
sudo apt install ca-certificates curl
ca-certificates lets apt verify Docker’s TLS certificate, and curl downloads the GPG key. Both are usually present already; apt will just confirm.
Then remove any unofficial Docker packages, so they don’t clash with Docker’s. This is the command from Docker’s install page:
serversudo apt remove $(dpkg --get-selections docker.io docker-compose docker-compose-v2 docker-doc docker-buildx podman-docker containerd runc | cut -f1)
On a fresh server apt may report that none of these are installed. That’s fine.
If it fails: apt update errors with a repository problem. Fix the source first — the Docker steps will not work with a broken apt state.
Add Docker’s GPG key and apt repository
Create the directory for the key, download Docker’s key into it, and make it readable:
serversudo 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
Then add the repository. Docker now writes it as a docker.sources file. The Suites: line fills in your release’s codename — noble on 24.04 — so you don’t have to know it:
serversudo 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 Signed-By line pins the repository to that key, so apt only trusts packages from it that carry Docker’s signature. That’s the security point of this step — don’t drop that line.
If it fails: NO_PUBKEY or a GPG error on apt update. The key didn’t land in /. Redo the curl line, check the path, then apt update again.
Install Docker Engine, the CLI and the Compose plugin
One command installs the whole set:
serversudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
docker-ceis the Engine, the daemon that builds and runs containers.docker-ce-cliis thedockercommand you type.containerd.iois the runtime underneath.- The buildx and compose plugins add
docker buildxanddocker composeas subcommands, not separate programs.
Answer yes when apt asks. Docker starts by itself once the packages are in. Check with:
serversudo systemctl status docker
Check: active (running). If it isn’t running, start it with sudo systemctl start docker.
Run Docker without sudo
By default only root can talk to the Docker daemon. Add yourself to the docker group:
serversudo usermod -aG docker $USER
Then log out and back in — or run newgrp docker in that session — so the new group takes effect.
The docker group is not cosmetic. Docker’s post-install page warns that the group grants root-level privileges, because the daemon always runs as root. Only add users you trust with the whole server.
Docker’s own docs flag the docker group as root-level access. Source: docs.docker.com, captured Nov 20, 2026.
If it fails: You skip the re-login and see permission denied while trying to connect to the Docker daemon socket. Log out and back in, or run newgrp docker, then try again.
Verify the install with hello-world
Run Docker’s test image:
serverdocker run hello-world
Check: A message starting with Hello from Docker!, followed by an explanation of what just happened. This message confirms Docker pulled the image, created a container, ran it, and exited — the whole pipeline works.
Run a real container and reach it from your browser
hello-world exits immediately. To see Docker serve something, run nginx and publish port 8080:
serverdocker run -d --name nginx-test -p 8080:80 nginx
curl http://localhost:8080
-d runs it in the background, -p 8080:80 maps your server’s port 8080 to port 80 inside the container, and curl should print the nginx welcome page. Then clean up:
serverdocker stop nginx-test && docker rm nginx-test
Make sure Docker starts on boot
Docker’s docs say that on Debian and Ubuntu the Docker service starts on boot by default. Confirm it:
serversystemctl is-enabled docker.service containerd.service
Both lines should read enabled. If either doesn’t, turn it on:
serversudo systemctl enable docker.service
sudo systemctl enable containerd.service
Reboot the server once and run docker ps. If it works after a reboot, Docker is installed for good.
Key takeaways
- Install Docker on Ubuntu from Docker’s official apt repository, not Ubuntu’s
docker.iopackage — remove the old packages, add the GPG key and the repo, thenapt install docker-ce. - Join the
dockergroup to skipsudo, and remember it’s root-equivalent — only add yourself. - Confirm with
docker run hello-world, then a real container like nginx. - Published ports (
-p 8080:80) bypass UFW. Bind to127.0.0.1or use a reverse proxy for anything that shouldn’t be public. - On Ubuntu, Docker starts on boot by default; check with
systemctl is-enabledand reboot once to be sure.
A VPS for this guide
Everything above runs on a VPS with 2 GB of RAM or more. The cheapest 2 GB+ plan at each provider whose prices we read every day, IPv4 included:
| Plan · provider | vCPU · RAM · disk | You pay | Visit |
|---|---|---|---|
1 slice InterServer · New York +2 | 1 vCPU·2 GB·40 GB | $3.00/mo | |
KVM VPS Special 2 GB RackNerd · New York +3 | 2 vCPU·2 GB·35 GB | $3.00/mo | |
VPS nano G11.5s netcup · Nuremberg | 2 vCPU·2 GB·60 GB | $3.36/mo | |
SSD VPS 2 CloudCone · USA | 4 vCPU·2 GB·60 GB | $3.83/mo | |
NVMe 2 GB HostHatch · Amsterdam +15 | 1 vCPU·2 GB·10 GB | $4.00/mo |
Prices read Dec 4, 2026. gets that provider's deals on Telegram. Compare every 2 GB plan →
Docker, UFW and published ports
Here’s the gotcha. When you publish a port with -p 8080:80, Docker adds its own iptables rules, and traffic to that container is routed before it reaches the rules UFW manages. The result: the port is reachable from the internet even if UFW denies it.
Docker’s “Docker and ufw” documentation says the two are incompatible: published ports are diverted in the nat table before they hit the INPUT and OUTPUT chains UFW uses, “effectively ignoring your firewall configuration.” Docker’s install page repeats the warning before you even start.
Published ports skip UFW’s chains entirely, in Docker’s own words. Source: docs.docker.com, captured Nov 20, 2026.
Two clean ways to stay safe:
- Bind to localhost when the container doesn’t need public access:
docker run -p 127.0.0.1:8080:80 .... Only your server can reach it, and you put a reverse proxy in front. - Keep the port internal with
--networkisolation and no-pat all, or route traffic through a proxy you control.
If you do need a published port, set up the firewall first and understand what you’re opening. For rules that apply to container traffic, Docker’s docs point to the DOCKER-USER iptables chain rather than UFW.
Common Docker install problems
permission denied while trying to connect to the Docker daemon socket.You’re not in the docker group, or you haven’t logged out and back in since usermod. Run groups to check, then newgrp docker.
E: Unable to locate package docker-ce.The repository wasn’t added, or apt update after it failed. Recheck the /etc/apt/sources.list.d/docker.sources file and the key, then apt update.
NO_PUBKEY on apt update.The GPG key is missing or was saved to the wrong path. Redo step 2’s curl line and run apt update again.
docker: Error response from daemon: ... bind: address already in use.Something already listens on that host port. Pick another port in -p, or find the process with sudo ss -tlnp.
A port you blocked in UFW is still reachable.This is the published-port problem above: Docker’s rules run first, so UFW never gets a say. Bind the port to 127.0.0.1 or drop the -p. If a site won’t load from outside, check the provider panel’s network firewall as well as sudo ufw status.
After you install Docker: going further
- Compose.
docker composeis already installed (step 3). Put acompose.yamlfile in a project folder anddocker compose up -drebuilds a whole stack from scratch. - A real first project. Our self-host n8n guide runs n8n in Docker, and it shows the memory, ports and persistence decisions you’ll hit with any container app.
- Images and updates. Learn
docker pulland tag your images by version. A tag likenginxmeanslatest, which changes under you; pin versions in production. - Picking a server. If you haven’t bought one yet, compare VPS prices by real monthly cost — renewal price and setup fees included.
Questions
What’s the difference between Docker Engine and Docker Desktop?
Docker Engine is the daemon and CLI that run on a Linux server — what this guide installs. Docker Desktop is a desktop app for macOS, Windows and Linux that bundles the Engine with a GUI. On a VPS you want the Engine.
Can I install Docker on Ubuntu without sudo?
You need sudo once to install the packages and add yourself to the docker group. After that, group members run docker without sudo. The daemon still runs as root, which is why the group matters.
Is Docker free on Ubuntu?
Docker Engine and the CLI are free and open source. Docker Desktop needs a paid subscription for commercial use at larger companies (more than 250 employees or more than $10 million a year in revenue), but a server install doesn’t use Desktop.
Does this work on Ubuntu 22.04 or 26.04?
Yes. Docker’s install page lists 22.04, 24.04 and 26.04 LTS. The commands are identical; the Suites: line resolves to jammy or resolute instead of noble, which gives you the right repository.
Why is my container’s port reachable even though UFW blocks it?
Docker adds its own iptables rules that run before UFW, so published ports bypass it. Bind to 127.0.0.1 or route through a proxy if that port shouldn’t be public.
How much RAM does my VPS need for Docker?
Docker itself needs very little. Budget for the containers: a couple of small apps run happily in 2 GB, and anything handling big datasets or builds wants 4 GB or more.
How we checked: The commands follow Docker’s official installation page for Ubuntu (apt repository method), the Linux post-install page for the docker group and start-on-boot, and Docker’s packet filtering and firewalls page for UFW and published ports, all read on 2026-11-14. We did not run the steps on every provider’s images, but the procedure is the same on any Ubuntu 24.04 server. How we check.