Docker & DevOps

Install Docker Engine and Docker Compose on a Linux VPS

Install Docker Engine and the Compose plugin from Docker's official repository on Ubuntu, Debian, AlmaLinux or Rocky, set log limits and run your first container.

BeginnerLinux VPS3 min read

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 (or dnf remove podman buildah on RHEL systems, if you do not need them).

Install on Ubuntu or Debian

  1. Add Docker's GPG key and repository:
    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.list
    On Debian, replace ubuntu with debian in both URLs.
  2. 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-core
dnf config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo
dnf install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

Then start Docker and enable it at boot:

systemctl enable --now docker

Verify the installation

docker run --rm hello-world
docker compose version

The 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 deploy

The 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-stopped

Start 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

CommandDoes
docker psRunning containers (-a for all)
docker compose up -d / downStart / stop a project
docker compose logs -fFollow logs
docker compose pullDownload newer images
docker exec -it name shShell inside a container
docker system dfDisk used by images, containers, volumes
docker system pruneRemove 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 --allowerasing to the install.
  • Docker fails to start on a VPS: the virtualisation type may not support it. Check with systemd-detect-virt; kvm works, openvz and lxc often 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.

Next steps

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.