Short answer
The most reliable way to install Docker on a VDS is to add Docker’s official apt repository and install docker-ce, docker-ce-cli, containerd.io, docker-buildx-plugin and docker-compose-plugin. Docker Compose ships with these packages and runs as docker compose (with a space), so there is nothing extra to download. After installing, take care of three things: publish ports the right way, cap container logs and decide how you will update.
The commands are for Ubuntu and Debian; AlmaLinux and Rocky Linux differences have their own section. Commands run as root; if you log in as a sudo user, prefix them with sudo. If you have not connected to the server yet, start with “How to connect to a VDS via SSH”.
Is your VDS ready to run Docker?
Docker relies on the cgroups and namespaces features of the Linux kernel. The server has to boot its own kernel, which means full virtualization such as KVM. Check these before installing:
- Virtualization type: if systemd-detect-virt prints kvm, vmware or microsoft, you are fine. If it prints openvz or lxc, Docker may not run. The difference between the two models is explained in “VDS vs VPS: are they the same?”.
- Operating system: it must be 64-bit (x86_64 or arm64) and a release listed on Docker’s install page. cat /etc/os-release shows the release and uname -m the architecture. Older releases that have dropped off the list (Ubuntu 20.04, for example) no longer get current packages.
- Memory: Docker itself uses little memory; the load comes from the containers. To run several services together with Docker Compose, such as n8n, PostgreSQL and Redis, TR-VDS #3 with 2 vCores and 8 GB RAM is a good starting point. The full calculation is in “How much RAM and how many vCPUs does a VDS need? Sizing guide”.
- Disk: images, container layers and volumes pile up under /var/lib/docker. WeServer Turkey VDS plans range from 20 GB to 200 GB SSD; with a few images and a database, 20 GB can get tight.
Docker’s official repository or the distribution’s docker.io package?
Ubuntu and Debian also ship a package called docker.io in their own repositories. apt install docker.io installs it in one command, but its version follows the distribution’s release cycle and often lags behind Docker’s current release. The Compose plugin comes under different package names there too (docker-compose-v2 on Ubuntu).
Docker’s own repository delivers current Engine and Compose releases and security fixes directly, and Docker’s documentation assumes this setup. Do not mix the two sources on one server; if docker.io is installed, remove it first. The get.docker.com script adds the same repository, and Docker recommends it for test and development environments. Doing the steps by hand on a production server shows you exactly what gets installed and from where.
How do you install Docker on Ubuntu step by step?
- 1. Remove old packages that could conflict: for p in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do apt-get remove -y $p; done. apt just warns about packages that are not installed and moves on. Existing images and volumes under /var/lib/docker are not deleted.
- 2. Add the required tools and Docker’s signing key: apt-get update && apt-get install -y ca-certificates curl, then install -m 0755 -d /etc/apt/keyrings, curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc and chmod a+r /etc/apt/keyrings/docker.asc.
- 3. Define the repository: 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. The command reads the release codename (noble, for example) from the server itself.
- 4. Install the packages: apt-get update && apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin.
- 5. Check the service: systemctl status docker should show “active (running)”. On Ubuntu and Debian the service starts on install and is enabled at boot; if it did not start, run systemctl enable --now docker.
- 6. Test it: docker run --rm hello-world pulls and runs a small test image and prints a message starting with “Hello from Docker!”. docker version and docker compose version show the installed versions.
What is different on Debian, AlmaLinux and Rocky Linux?
- Debian: the steps are the same; just replace ubuntu with debian in two URLs: https://download.docker.com/linux/debian/gpg and https://download.docker.com/linux/debian in the repository line. The codename (bookworm or trixie, for example) still comes from /etc/os-release.
- AlmaLinux and Rocky Linux: dnf -y install dnf-plugins-core, dnf config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo, then dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin. The service does not start on its own on these distributions, so run systemctl enable --now docker.
- These distributions may come with podman and runc installed. If they conflict with the Docker packages, remove them with dnf remove podman runc.
- On a server running firewalld, Docker creates its own docker zone. Ports you publish can be reachable from outside regardless of your firewalld rules, so the port warning below applies here as well.
Is it safe to use Docker without sudo?
Docker commands talk to the /var/run/docker.sock socket, which belongs to root. Add a user to the docker group and they can run Docker without typing sudo: usermod -aG docker username, then log out and back in. Group changes do not reach sessions that are already open.
The docker group effectively grants root. A member can mount the host’s root directory into a container and change any file. Give this group only to people who already have sudo on the server. If you want Docker to run without root, there is rootless mode; in that mode some network features, such as publishing ports below 1024, need extra setup.
How do you run a first project with Docker Compose?
Compose describes several containers in a single compose.yaml file. The example below sets up an Nginx container that is reachable only from inside the server:
- 1. Create the project folder: mkdir -p /opt/example/html && echo hello > /opt/example/html/index.html && cd /opt/example.
- 2. Write the file with nano compose.yaml. Contents: a service called web under services, with image: nginx:stable, "127.0.0.1:8080:80" in the ports list, "./html:/usr/share/nginx/html:ro" in the volumes list and restart: unless-stopped. YAML’s one-line flow style works too: services: {web: {image: nginx:stable, ports: ["127.0.0.1:8080:80"], volumes: ["./html:/usr/share/nginx/html:ro"], restart: unless-stopped}}
- 3. Start it: docker compose up -d. -d runs the containers in the background. docker compose ps shows their status, and docker compose logs -f web follows the log.
- 4. Test it: curl http://127.0.0.1:8080 should return “hello”. Because the port is bound to 127.0.0.1, the same address does not open from outside.
- 5. restart: unless-stopped brings the container back when the server reboots. A container you stopped by hand stays stopped.
- 6. Stop it: docker compose down removes the containers and the project network but keeps named volumes. Adding -v removes the volumes too; if a volume holds a database, the data goes with it.
What should you configure after installing Docker?
- Port publishing and UFW: Docker writes its own iptables rules for ports published with ports, and those rules are processed before UFW’s. Even with ufw deny 8080, a port published as 8080:80 stays open to the internet. Publish services meant for local access as 127.0.0.1:8080:80 and expose them through Nginx. Nginx and SSL setup is covered in “How to point a domain to a VDS (A record, Nginx and free SSL)”; set proxy_pass in its reverse proxy section to http://127.0.0.1:8080.
- Log size: the default json-file driver lets container logs grow without limit. Put {"log-driver": "json-file", "log-opts": {"max-size": "10m", "max-file": "3"}} in /etc/docker/daemon.json and run systemctl restart docker. The setting applies only to newly created containers; for existing ones, run docker compose up -d --force-recreate in the project folder.
- Disk usage: docker system df shows how much space images, containers and volumes take. docker image prune -a deletes images that no container uses. What to do when the disk fills up is covered in “How to fix a full disk on a Linux server (df, du and log cleanup)”.
- Updates: Docker Engine is updated through apt (apt-get update && apt-get upgrade). The service restarts during the upgrade, and containers with a restart policy come back up. To update images, run docker compose pull && docker compose up -d in the project folder.
- Backups: volumes live under /var/lib/docker/volumes. Do not copy a volume that holds a database as plain files; take a dump from inside the container with docker compose exec. Details are in “How to back up a VDS (automatic backups with rsync, restic and cron)”.
Which Docker installation errors come up, and how do you fix them?
- “permission denied while trying to connect to the Docker daemon socket”. Cause: the user is not in the docker group, or the session was not refreshed after adding them. Fix: look for docker in the output of id; if it is missing, add it with usermod -aG docker and reconnect.
- “Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?”. Cause: the service is not running or failed on start. Fix: read the error with systemctl status docker and journalctl -u docker -n 50. A single typo in daemon.json is enough to stop the service from starting.
- “docker-compose: command not found”. Cause: Compose v2 installs as a docker subcommand, not as a separate program. Fix: type docker compose up -d, and update any old scripts that call docker-compose.
- “Bind for 0.0.0.0:80 failed: port is already allocated” or “address already in use”. Cause: the port is taken by another container or by Nginx or Apache on the server. Fix: find the process holding it with ss -tlnp | grep :80 and publish the container on another port.
- “Conflicting values set for option Signed-By”. Cause: the Docker repository is defined in two files with different key paths. Fix: delete one of the Docker entries under /etc/apt/sources.list.d/ and run apt-get update.
- “toomanyrequests: You have reached your pull rate limit”. Cause: Docker Hub limits anonymous image pulls per IP. Fix: sign in to your Docker Hub account with docker login.
- UFW shows the port as closed, yet the container is reachable from outside. Cause: Docker’s iptables rules are processed before UFW. Fix: publish the port on 127.0.0.1, or drop the ports line and reach the service only from inside the Docker network.
Frequently asked questions
What is the difference between docker-compose and docker compose? docker-compose is the old Compose v1 written in Python, which stopped receiving updates in 2023. docker compose is v2, shipped as a Docker CLI plugin; it reads both compose.yaml and older docker-compose.yml files.
How do you remove Docker completely? apt-get purge docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin removes the packages. Images, containers and volumes stay under /var/lib/docker and /var/lib/containerd; to delete them too, run rm -rf /var/lib/docker /var/lib/containerd. This permanently deletes the data in your volumes.
Can containers get IPv6 addresses on an IPv6 Subnet VDS? Yes. You enable IPv6 in /etc/docker/daemon.json and give containers a smaller slice from inside your /64. Choosing the slice is covered in “IPv6 /48 vs /64 subnet: what is the difference and which should you choose?”.
Can you install Docker on a Windows Server VDS? Most images on Docker Hub are Linux images and need a Linux kernel. If that is what you plan to run, pick a VDS with Ubuntu or Debian. On Windows Server, Docker runs Windows containers only, with a separate installation.
Does Docker slow the server down? Containers are not virtual machines; they share the host kernel, and Docker’s own overhead is small. Slowness usually comes from the containers’ memory and CPU use; docker stats shows each container’s live consumption.
