GuidesGetting started

How to install Docker on Ubuntu (22.04, 24.04, 26.04, 26.10)

Install Docker Engine from Docker's apt repository, run it without sudo, fix the permission-denied socket error, and stop published ports skipping ufw.

December 4, 2026The Everpod team
The short answer

Install Docker Engine from Docker’s own apt repository: add its signing key, add the repository, install docker-ce with its CLI, containerd and the Buildx and Compose plugins, and check it with sudo docker run hello-world. As of December 2026 Docker supports 64-bit Ubuntu 22.04, 24.04, 26.04 and 26.10, and the current Engine is 29.10.1 (November 24, 2026). To run docker without sudo, add yourself to the docker group and log in again, knowing that Docker’s docs say the group “grants root-level privileges”. On a server, two defaults need changing early: published ports skip ufw, so publish them to 127.0.0.1, and container logs grow without limit until you set rotation.

Which Ubuntu versions, and which package

Docker’s Ubuntu install page lists four 64-bit releases as of December 2026: 26.10 (Stonking), 26.04 LTS (Resolute), 24.04 LTS (Noble) and 22.04 LTS (Jammy), on amd64, arm64, armhf, s390x and ppc64le. Ubuntu 26.04 is supported. Derivatives such as Linux Mint are not officially supported, though the packages often work there.

There are three places a Docker can come from on Ubuntu:

SourcePackageBuilt byVersion, December 2026
Docker’s apt repository
docker-ce and pluginsDocker29.10.1
Ubuntu’s archive
docker.ioUbuntu29.1.3 on 22.04, 24.04 and 26.04 (updates pocket); 29.7.2 on 26.10
Snap Store
docker snapCanonical29.8.0

Docker’s page calls the distribution’s packages unofficial and warns they “may conflict with the official packages provided by Docker”, so it tells you to remove docker.io, docker-compose, docker-compose-v2 and podman-docker before installing its own. Ubuntu’s docker.io is a working Docker, but it trails Docker’s releases (29.1.3 against 29.10.1 today), and Docker’s own docs are written for Docker’s packages. Docker’s page does not mention the snap at all. Its store page says it is built by Canonical and “not endorsed or published by Docker, Inc.”, and its README says every file Docker needs to reach must live under your home directory, so a bind mount from /srv or /opt is out of its reach. On a server, use Docker’s repository.

Install Docker Engine from Docker’s apt repository

First remove any conflicting packages. This uninstalls whichever of them are present; apt may report that none are. Images, containers and volumes under /var/lib/docker stay where they are:

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

Then add Docker’s signing key and its repository. The last part writes /etc/apt/sources.list.d/docker.sources (overwriting it if it exists) and fills in your release’s codename and your architecture by itself, so the block is the same on every supported Ubuntu:

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.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
Copied

Install the Engine, the CLI, containerd, Buildx and the Compose plugin:

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

On Ubuntu the service starts by itself. Check that it is running and that containers work; the test downloads a small image, runs it, prints a confirmation message and exits:

sudo systemctl status docker
sudo docker run hello-world
Copied

Compose comes as a plugin, so the command is docker compose with a space, not the old docker-compose. docker compose version confirms it (Docker’s repository carries Compose 5.8.1 as of December 2026), and what docker compose up -d does is the next step for most people. Upgrades arrive with your normal sudo apt update && sudo apt upgrade. To hold a specific version, list them with apt list --all-versions docker-ce and install docker-ce= and docker-ce-cli= that version string.

The convenience script, and when it fits

Docker also publishes a script at get.docker.com that sets up the same repository and installs everything in one go. Docker says it is “only recommended for testing and development environments”: it installs the latest release without asking, which can mean an unexpected major version, and it is not built to upgrade an existing install. Read what it will do before running it:

curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh ./get-docker.sh --dry-run
Copied

Then, if you are happy with it:

sudo sh get-docker.sh
Copied

For a throwaway VM it saves a minute. For a server you will keep, the manual steps above give the same packages and leave you knowing where they came from. Either way, later upgrades go through apt, not through the script again.

Run docker without sudo, and what that gives away

The daemon’s socket, /var/run/docker.sock, is open to root and the docker group, so joining the group is how you drop sudo. Know the cost before you do it. Docker’s post-install page is blunt: “The docker group grants root-level privileges to the user.” Its security page explains why: a container can mount the host’s / and alter the host filesystem without restriction. Anyone who can run docker can make themselves root, password or no password.

If you accept that for this user, add them. If groupadd reports that the group already exists, carry on with the second line:

sudo groupadd docker
sudo usermod -aG docker $USER
Copied

Group membership is read when you log in, so log out and back in (for SSH, open a new connection; a tmux server started earlier keeps the old groups until it is restarted), or run newgrp docker for the current shell. Then docker run hello-world works without sudo.

When the user is a coding agent

On a server where Claude Code, Codex or another agent runs commands as your user, adding that user to docker means the agent can do anything root can, whatever its own permission rules say about sudo. That can be the right call on a machine that exists for the agent and holds nothing else of value; it is a poor one on a server with other people’s data or credentials you would not hand the agent directly. The ways to weigh it:

Rootless mode

Rootless mode runs a separate daemon and its containers as an ordinary user, inside a user namespace. It needs newuidmap and newgidmap (the uidmap package) and at least 65,536 subordinate IDs for the user in /etc/subuid and /etc/subgid (grep ^$(whoami): /etc/subuid shows them). Docker suggests stopping the system-wide daemon first. This turns it off and deletes its socket file:

sudo apt install uidmap docker-ce-rootless-extras
sudo systemctl disable --now docker.service docker.socket
sudo rm /var/run/docker.sock
Copied

Then, as the user who will run Docker (not with sudo):

dockerd-rootless-setuptool.sh install
systemctl --user start docker.service
Copied

The setup tool prints a DOCKER_HOST line pointing at /run/user/<uid>/docker.sock and creates a rootless CLI context; docker info should list rootless under Security Options. A user service stops when the user logs out unless lingering is on, which on a server you want: sudo loginctl enable-linger $USER (more in keeping a user service running after logout). Rootless mode’s own settings file is ~/.config/docker/daemon.json, not the one in /etc/docker.

The errors people hit right after installing

“permission denied while trying to connect”

Docker 29 clients print:

permission denied while trying to connect to the docker API at unix:///var/run/docker.sock
Copied

and Docker 28 and earlier print the same thing as:

permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock
Copied

Your user is not in the docker group, or is but the shell predates it. Check with id -nG; if docker is missing, add it as above, and if usermod already ran, log in again. Do not chmod 666 the socket: that hands root-level access to every account and process on the machine.

A related warning appears if you ran Docker with sudo before joining the group:

WARNING: Error loading config file: /home/user/.docker/config.json -
stat /home/user/.docker/config.json: permission denied
Copied

sudo left ~/.docker owned by root. Give it back to yourself (or delete the directory, losing any settings and registry logins in it):

sudo chown "$USER":"$USER" /home/"$USER"/.docker -R
sudo chmod g+rwx "$HOME/.docker" -R
Copied

“Cannot connect to the Docker daemon”

Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
Copied

This one is about the daemon, not your permissions. Check it, start it, and make it start at boot:

sudo systemctl is-active docker
sudo systemctl start docker
sudo systemctl enable docker.service containerd.service
Copied

If it will not start, sudo journalctl -u docker.service -e shows why; if you have just edited /etc/docker/daemon.json, check that it is still valid JSON. If the daemon is running and the error stays, the client may be looking elsewhere: env | grep DOCKER_HOST shows a leftover setting (from a rootless trial, say), and unset DOCKER_HOST plus removing it from ~/.bashrc or ~/.profile clears it. In rootless mode the address differs, so the message names a socket under /run/user/, and the fix is systemctl --user start docker.service.

Published ports go around ufw

This surprises nearly everyone who installs Docker on a server with a firewall. Docker’s install page says that with ufw or firewalld, ports you publish “bypass your firewall rules”, and its firewall page explains that Docker diverts the traffic before it reaches the chains ufw uses. Its port-publishing page adds that -p 8080:80 publishes to every address on the host, 0.0.0.0 and [::], and says plainly: “Publishing container ports is insecure by default.” A ufw deny 8080 does not stop it.

That matters doubly where agents run, because they start web apps, databases and dev servers in containers as a matter of course, often with a ports: line copied from a README. Publish to loopback instead, so only the server itself can reach the port:

docker run -p 127.0.0.1:8080:80 nginx
Copied

In a Compose file, the same thing is the address in front of the ports:

services:
  web:
    image: nginx
    ports:
      - "127.0.0.1:8080:80"
Copied

You then open it from your laptop through an SSH tunnel or a private network such as Tailscale, as in opening a localhost app on a remote server. To make loopback the default when a port names no address, set it in /etc/docker/daemon.json (merged with any keys already there) and restart Docker, which interrupts the running containers. Docker reads two settings for this: ip covers the default bridge network that a plain docker run uses, and default-network-opts covers bridge networks you or Compose create, which a Compose project runs on:

{
  "ip": "127.0.0.1",
  "default-network-opts": {
    "bridge": {
      "com.docker.network.bridge.host_binding_ipv4": "127.0.0.1"
    }
  }
}
Copied

A network option is set when the network is made, so a Compose project already running keeps its old default until its network is recreated: docker compose down removes the project’s containers and network (its named volumes stay), and docker compose up -d makes them again.

Docker releases before 28.0.0 let other machines on the same network segment reach even ports published to 127.0.0.1, so a server still on an older Docker should upgrade. To check what the world can actually see, the open-ports check runs the scan from outside, which is the only view that settles it.

Stop container logs filling the disk

By default every container logs through the json-file driver, whose max-size defaults to unlimited. A chatty container left running for weeks (a dev server in a loop, an agent’s tool service with debug logging) grows one file under /var/lib/docker/containers/ until the disk is full, and then everything on the server fails at once. Cap it in /etc/docker/daemon.json, merged with any keys already there:

{
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  }
}
Copied

Restart the daemon to apply it:

sudo systemctl restart docker
Copied

Restarting the daemon interrupts the containers running on it, so pick a quiet moment. The limit applies only to containers created after the change: existing ones keep unlimited logs until you recreate them (docker compose up -d --force-recreate for a Compose project). max-file does nothing unless max-size is set. The alternative is the local driver ("log-driver": "local"), which rotates and compresses by default and keeps 100 MB per container.

To see where the space has gone, docker system df totals images, containers and volumes, and what a container keeps and forgets explains which of those you can safely prune.

Uninstalling

Removing the packages leaves your data. The second line below deletes every image, container and volume on the machine for good, so run it only if you mean that; the third deletes Docker’s repository entry and signing key:

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/containerd
sudo rm /etc/apt/sources.list.d/docker.sources /etc/apt/keyrings/docker.asc
Copied

A daemon.json you edited stays in /etc/docker until you delete it yourself.

Run Claude Code, Codex, OpenCode, Pi, Hermes or OpenClaw on an always-on developer pod.

A developer pod is a permanent cloud computer (VPS), set up and secured for you, with your pick of Claude Code, Codex, OpenCode, Pi, Hermes and OpenClaw installed. Run more agents at once than your laptop can hold, and keep them working when it’s closed. From $24 a month, built in about ten minutes.