Docker runs applications in containers so they behave the same on every server. Distribution packages are often outdated, so the recommended way to install Docker on a Linux VPS is Docker's own repository, which also provides the docker compose plugin.
Before you start
- A KVM VPS (container-based VPS types usually cannot run Docker) with root or sudo access.
- A 64-bit Ubuntu 22.04/24.04, Debian 12, AlmaLinux 8/9 or Rocky Linux 8/9.
- Remove old unofficial packages if present:
apt remove docker.io docker-compose podman-docker(ordnf remove podman buildahon RHEL systems, if you do not need them).
Install on Ubuntu or Debian
- Add Docker's GPG key and repository:On Debian, replace
apt update && apt install ca-certificates curl install -m 0755 -d /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo $VERSION_CODENAME) stable" > /etc/apt/sources.list.d/docker.listubuntuwithdebianin both URLs. - Install the packages:
apt update && apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Install on AlmaLinux or Rocky
dnf install dnf-plugins-corednf config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repodnf install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-pluginThen start Docker and enable it at boot:
systemctl enable --now dockerVerify the installation
docker run --rm hello-worlddocker compose versionThe first command downloads a tiny image and prints a welcome message.
Limit container log size
By default container logs grow without limit and can fill the disk. Create /etc/docker/daemon.json:
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
}
}Restart Docker with systemctl restart docker. The limit applies to containers created afterwards.
Run Docker as a non-root user
usermod -aG docker deployThe user must log out and in again. Be aware that membership in the docker group is effectively root access to the host, so only add trusted users. Rootless Docker is an alternative for stricter setups.
Your first Compose project
Create a folder with docker-compose.yml:
services:
web:
image: nginx:1.27-alpine
ports:
- "127.0.0.1:8080:80"
restart: unless-stoppedStart it with docker compose up -d and test with curl http://127.0.0.1:8080. Publishing on 127.0.0.1 keeps it private until you put a reverse proxy with HTTPS in front.
Essential commands
| Command | Does |
|---|---|
docker ps | Running containers (-a for all) |
docker compose up -d / down | Start / stop a project |
docker compose logs -f | Follow logs |
docker compose pull | Download newer images |
docker exec -it name sh | Shell inside a container |
docker system df | Disk used by images, containers, volumes |
docker system prune | Remove stopped containers and unused images |
Troubleshooting
- permission denied while trying to connect to the Docker daemon socket: use sudo or add the user to the docker group and log in again.
- Published ports reachable despite UFW: Docker bypasses UFW rules. Bind ports to 127.0.0.1 or filter in the DOCKER-USER chain.
- Conflicting packages on AlmaLinux (podman, runc): remove them or add
--allowerasingto the install. - Docker fails to start on a VPS: the virtualisation type may not support it. Check with
systemd-detect-virt;kvmworks,openvzandlxcoften do not.
Docker install FAQ
docker-compose or docker compose?
Use docker compose (with a space), the current plugin. The old standalone docker-compose v1 is no longer maintained.
How much RAM does Docker need?
Docker itself uses little; plan RAM for the containers you run. 1–2 GB suits a few small services.
Can I use Docker on cPanel hosting?
No, Docker needs root access on a VPS or dedicated server.
