KVM VPSKVM VPS

Install Docker and Docker Compose on a Linux VPS

Complete guide to installing Docker and Docker Compose on a Linux VPS at Lordhosting: official repository, running without sudo, your first docker-compose.yml and deploying Portainer.

Docker has become the standard tool for deploying applications in an isolated, reproducible way: a game server, a database, a Discord bot or a panel like Pterodactyl each live in their own container, without cluttering the host system. This guide installs Docker Engine and Docker Compose on a Debian or Ubuntu VPS from the official repository, then deploys a first container to confirm everything works.

⚙️ Requirements

  • A Lordhosting KVM VPS (Debian 11/12 or Ubuntu 22.04/24.04 recommended)
  • SSH access with a user that has sudo rights
  • Ideally, an already-hardened VPS — see our Secure a Linux VPS guide

⚙️ 1. Update the system

Always start by patching installed packages and adding the dependencies the Docker repository needs:

sudo apt update && sudo apt upgrade -y
sudo apt install -y ca-certificates curl gnupg

⚙️ 2. Add the official Docker repository

The official repository guarantees an up-to-date version, unlike the docker.io package from the Debian repos which often lags behind. Add the GPG key:

sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg | \
  sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
Debian or Ubuntu?

The commands above target Debian. On Ubuntu, replace debian with ubuntu in the GPG key URL and in the repository line below. Everything else is identical.

Then add the repository to your APT sources:

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
  https://download.docker.com/linux/debian $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

⚙️ 3. Install Docker Engine and Compose

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

The docker-compose-plugin package provides the modern docker compose command (two words) — nothing else to install.

⚙️ 4. Verify the installation

sudo docker run hello-world
docker compose version

If hello-world prints its welcome message and the Compose version shows up, Docker is up and running.

⚙️ 5. Run Docker without sudo (optional)

To avoid typing sudo on every command, add your user to the docker group:

sudo usermod -aG docker $USER

Log out and back in (or run newgrp docker) for the change to take effect.

The docker group = root rights

Any member of the docker group can gain root access on the machine. Only add trusted users to it.

⚙️ 6. Your first docker-compose.yml

Compose describes a full stack in a single file. Create a folder and a file:

mkdir ~/portainer && cd ~/portainer
nano docker-compose.yml

Paste this example, which deploys Portainer, a web interface to manage your containers by hand:

services:
  portainer:
    image: portainer/portainer-ce:latest
    container_name: portainer
    restart: unless-stopped
    ports:
      - "9443:9443"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - portainer_data:/data

volumes:
  portainer_data:

Start the stack:

docker compose up -d

Portainer is reachable at https://your_ip:9443. Remember to open the matching port in your firewall:

sudo ufw allow 9443/tcp

⚙️ 7. Essential Docker commands

docker ps                 # running containers
docker ps -a              # all containers, even stopped
docker logs -f <name>     # follow a container's logs
docker compose up -d      # start a stack in the background
docker compose down       # stop and remove the stack
docker compose pull       # update images
docker exec -it <name> bash  # open a shell inside a container

⚙️ 8. Maintenance and cleanup

Unused images and volumes pile up and fill the disk. A periodic cleanup is worth it:

docker system df          # see how much space Docker uses
docker system prune -a    # remove unused images, containers and networks
prune is permanent

docker system prune -a removes every image not used by a running container. Make sure no stopped-but-useful stack depends on one before running it.

✅ Conclusion

You now have a VPS ready to run any containerized application: an up-to-date Docker Engine, Compose built in, sudo-less execution and a first Portainer stack to drive it all. The natural next step is to install a game panel like Pterodactyl or to deploy your own services — each in its own cleanly isolated container.

No server to host your containers yet? Check out our high-performance Ryzen VPS, KVM-based and delivered in minutes with full root access.


❗Always good to know

  • If a command fails or a container refuses to start, our support is here: open a ticket or drop by Discord.

Frequently asked questions

Back to KVM VPS
Was this article helpful?
Welcome Offer

Sign up now and enjoy 10% off on your first order by entering the promo code: WELCOME

Logo LordHostingLordhosting is a SASU with a share capital of €1,000. SIREN 105 383 988 RCS Paris.
Copyright © 2026 LordHosting.