How to Install Docker on Ubuntu (26.04, 24.04 and 22.04)

Key Takeaways
- ✓Install Docker from Docker's own apt repository, not Ubuntu's docker.io package.
- ✓The Compose plugin gives you docker compose (with a space).
- ✓Adding a user to the docker group grants root-level access.
- ✓Turn on log rotation so container logs don't fill the disk.
Table of Contents
- •How to Install Docker on Ubuntu (26.04, 24.04 and 22.04)
- •Supported Ubuntu Versions
- •Step 1: Remove Old or Conflicting Packages
- •Step 2: Add Docker’s apt Repository
- •Step 3: Install Docker Engine and Compose
- •Step 4: Verify the Installation
- •Step 5: Run Docker Without sudo
- •Step 6: Start Docker on Boot
- •Step 7: Turn On Log Rotation
- •The Firewall Gotcha: Docker Bypasses UFW
- •Alternative: The Convenience Script
- •Updating and Uninstalling Docker
- •Troubleshooting
- •Frequently Asked Questions
- •Run Docker Without Managing the Server
How to Install Docker on Ubuntu (26.04, 24.04 and 22.04)
The reliable way to install Docker on Ubuntu is from Docker’s own apt repository. You get the current Docker Engine, the Compose plugin and security updates through normal apt upgrade, instead of the older docker.io package from Ubuntu’s archive. This guide follows Docker’s official instructions step by step, then covers running Docker without sudo, starting it at boot, log rotation and the firewall gotcha that catches most people on a VPS.
Quick answer: remove old packages, add Docker’s GPG key and repository, then run sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin. Check it with sudo docker run hello-world.
Supported Ubuntu Versions
Docker Engine supports these 64-bit Ubuntu releases (checked on Docker’s install page, 26 October 2026):
Ubuntu 26.10
Ubuntu 26.04 LTS
Ubuntu 24.04 LTS (Noble)
Ubuntu 22.04 LTS (Jammy)
It runs on x86_64 (amd64), arm64, armhf, s390x and ppc64le, so the same steps work on most cloud VPS servers, including ARM machines. Check your version with lsb_release -a or cat /etc/os-release.
Step 1: Remove Old or Conflicting Packages
Ubuntu’s own repositories ship unofficial packages such as docker.io and podman-docker that conflict with Docker’s packages. Remove any that are installed:
sudo apt remove $(dpkg --get-selections docker.io docker-compose docker-compose-v2 docker-doc docker-buildx podman-docker containerd runc | cut -f1)If none are installed, apt simply reports that there is nothing to remove. Existing images and volumes in /var/lib/docker/ are not deleted by this step.
Step 2: Add Docker’s apt Repository
First add Docker’s official GPG key, so apt can verify the packages:
sudo apt update
sudo apt 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.ascThen add the repository. This writes a .sources file that picks your Ubuntu codename and CPU architecture automatically:
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 updateStep 3: Install Docker Engine and Compose
sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-pluginThis installs five packages:
| Package | What it does |
|---|---|
docker-ce | The Docker Engine daemon |
docker-ce-cli | The docker command |
containerd.io | The container runtime Docker uses underneath |
docker-buildx-plugin | BuildKit-based docker build and multi-platform builds |
docker-compose-plugin | Compose v2, used as docker compose (with a space) |
The service starts automatically after installation. Check it with sudo systemctl status docker.
Step 4: Verify the Installation
sudo docker run hello-world
docker --version
docker compose versionhello-world downloads a tiny test image, runs it, prints a confirmation message and exits. If you see “Hello from Docker!”, the engine, the image download and the container runtime all work.
Step 5: Run Docker Without sudo
By default only root can talk to the Docker daemon. To use docker as your normal user, add yourself to the docker group:
sudo groupadd docker
sudo usermod -aG docker $USER
newgrp docker
docker run hello-world(groupadd may say the group already exists; that’s fine.) Log out and back in if newgrp doesn’t take effect in your session.
Security note: Docker’s documentation warns that the docker group grants root-level privileges to the user. Only add accounts you would trust with root.
Step 6: Start Docker on Boot
On Ubuntu the services are normally enabled already, but you can make sure with:
sudo systemctl enable docker.service
sudo systemctl enable containerd.serviceStep 7: Turn On Log Rotation
The default json-file logging driver writes container logs to files on the host and, as Docker’s docs point out, they can eventually fill the disk. On a small VPS this is one of the most common causes of a “no space left on device” error months later. Set a size limit in /etc/docker/daemon.json:
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
}
}Then restart Docker with sudo systemctl restart docker. The limit applies to containers created after the change; recreate existing ones to pick it up. To read and clean logs, see our guide to tailing and clearing Docker logs.
The Firewall Gotcha: Docker Bypasses UFW
If you use UFW, know this before you publish ports: when you run a container with -p 8080:80, Docker adds its own iptables rules, and traffic to that port can reach the container even if UFW looks like it blocks it. Two safe habits:
Publish ports only on localhost when a reverse proxy sits in front:
-p 127.0.0.1:8080:80.Use your cloud provider’s firewall as an outer layer.
We explain the details in how to open ports on a VPS.
Alternative: The Convenience Script
Docker also publishes a one-line install script:
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.shDocker recommends it only for testing and development environments. For a server you’ll keep, use the repository method above so you know exactly what was installed and upgrades stay predictable.
Updating and Uninstalling Docker
Because Docker now comes from an apt repository, updates arrive with the rest of the system:
sudo apt update && sudo apt upgradeTo remove Docker completely, including all images, containers and volumes (this deletes data):
sudo apt purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin docker-ce-rootless-extras
sudo rm -rf /var/lib/docker /var/lib/containerdTroubleshooting
“permission denied while trying to connect to the Docker daemon socket”: your user isn’t in the
dockergroup yet, or the session hasn’t picked it up. Runnewgrp dockeror log in again.“Unable to locate package docker-ce”: the repository wasn’t added or
apt updatewasn’t run after adding it. Check/etc/apt/sources.list.d/docker.sources.“docker: unknown command: docker compose”: the Compose plugin isn’t installed. Install
docker-compose-plugin.Cannot connect to the Docker daemon: the service is stopped. Run
sudo systemctl start dockerand checkjournalctl -u dockerfor the reason.
Frequently Asked Questions
Should I install docker.io or docker-ce on Ubuntu?
Use docker-ce from Docker’s repository. docker.io is Ubuntu’s own package and is often older; Docker’s install guide asks you to remove it first because the two conflict.
Does Docker Compose come with Docker on Ubuntu?
Yes, if you install docker-compose-plugin as shown above. You then run it as docker compose (with a space). The old standalone docker-compose (with a hyphen) is no longer needed.
How much RAM does Docker need on Ubuntu?
The engine itself is light; what you need depends on your containers. A database and a web app together usually need at least 1–2 GB of RAM to run comfortably.
Can I install Docker on Ubuntu WSL?
Yes. The same apt steps work inside an Ubuntu WSL 2 distribution, or you can use Docker Desktop on Windows with WSL 2 integration.
Is Docker free on Ubuntu?
Docker Engine is open source and free to use on Linux servers. Docker Desktop has its own licence terms for larger companies, but you don’t need Desktop on an Ubuntu server.
Run Docker Without Managing the Server
If you want root access and your own Docker host, RackUp’s Developer VPS gives you 8 vCPU, 12 GB RAM, 150 GB NVMe and 32 TB of monthly bandwidth for $35 a month, with full root access. If you’d rather skip server work entirely, Cloud Apps run your Dockerfile in a container with a private database and deploy on every Git push, from $2.44 a month. Compare plans.
Unsure Which Cloud Hosting Plan Fits Your Site?
Answer 4 quick diagnostic questions to estimate the server CPU, RAM and storage you need with transparent pricing.
Cloud Infrastructure Engineer.
Related Posts
DevOps & TutorialsHow to Point Custom Domain & Setup Free SSL on Oracle Cloud VPS
Learn how to point a custom domain to Oracle Cloud VPS and install free Let's Encrypt SSL with Certbot and Nginx in this complete step-by-step tutorial.
WordPress HostingHow to Install an SSL Certificate on WordPress (and Fix Mixed Content)
How to move a WordPress site to HTTPS: get a free certificate, update the site URLs, fix mixed content, force HTTPS at the server, and avoid the common redirect loop.
VPS HostingHow to Deploy Django to a VPS With Gunicorn and Nginx (Ubuntu)
Deploy Django to a VPS: Gunicorn as the app server managed by systemd, Nginx in front for static files and HTTPS, a firewall, and fixes for the usual 502 and static-file errors.