No KYC VPS
TutorialsOct 12, 20267 min readBy the No KYC VPS team

How to Install Docker and Docker Compose on an Ubuntu VPS

Install Docker Engine from the official repository, run it without sudo, launch a first Compose service and avoid the firewall trap that exposes ports.

Docker lets you run databases, web apps and tools in isolated containers, so installing something new never messes up the rest of your server. This guide installs Docker Engine and Docker Compose on Ubuntu and runs a first real service.

Terminal window on a VPS showing the commands used for installing Docker on an Ubuntu VPS, starting with “sudo apt update”
The kind of commands you will run on your server in this guide.

1. Install from Docker's repository

sudo apt update
sudo apt install -y 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

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" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

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

Check the install with sudo docker run hello-world.

2. Run Docker without sudo

sudo usermod -aG docker $USER
newgrp docker

Members of the docker group have effectively root-level power on the machine, so only add users you trust.

3. Your first Compose file

Create a folder and a compose.yaml that runs the Uptime Kuma monitoring tool:

mkdir -p ~/kuma && cd ~/kuma
cat > compose.yaml <<'EOF'
services:
  kuma:
    image: louislam/uptime-kuma:1
    restart: unless-stopped
    ports:
      - "127.0.0.1:3001:3001"
    volumes:
      - ./data:/app/data
EOF
docker compose up -d

Binding to 127.0.0.1 keeps the port off the public internet. Put a reverse proxy such as Nginx or Caddy in front when you want to reach it from outside.

Everyday commands

  • docker ps lists running containers.
  • docker compose logs -f follows the logs.
  • docker compose pull && docker compose up -d updates to newer images.
  • docker system prune removes unused images and stopped containers.
The steps of this guide in order: 1. 1. Install from Docker's repository; 2. 2. Run Docker without sudo; 3. 3. Your first Compose file; 4. Everyday commands; 5. A security warning about firewalls; 6. What to run next
The steps in this guide, in order.

A security warning about firewalls

Docker writes its own iptables rules. A port published as "8080:80" can be reachable from the internet even if UFW says it is blocked. Publish only what must be public, bind private services to 127.0.0.1 and test from outside with a port scanner.

Keep logs and disk under control

Container logs grow without limit by default. Cap them in /etc/docker/daemon.json:

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

Restart Docker with sudo systemctl restart docker. The setting applies to containers you create afterwards. Check disk use at any time with docker system df.

Troubleshooting

  • Permission denied on the Docker socket. Your user is not in the docker group yet, or you have not logged in again since adding it.
  • A container keeps restarting. Read its logs with docker logs container-name. A bad setting or a missing file is the usual cause.
  • Port already in use. Another program holds that port. Find it with sudo ss -tlnp and choose a different port.
  • Out of space. Run docker system df, then remove unused data with docker system prune.

Make sure it starts on boot

On Ubuntu the service is enabled automatically. Confirm with systemctl is-enabled docker, and turn it on with sudo systemctl enable --now docker if needed. Containers with restart: unless-stopped then come back after a reboot.

What to run next

Popular self-hosted apps include Nextcloud, Vaultwarden, Gitea, Plausible, n8n and Jellyfin. See our guide to self-hosting Nextcloud for a full example.

Frequently asked questions

Do I need to install Docker Compose separately?

No. The docker-compose-plugin package installed above adds the docker compose command.

Is it safe to add a user to the docker group?

Only for users you trust, because members of the group can gain root-level access to the machine.

How do I update a container?

Run docker compose pull and then docker compose up -d in the folder that holds the compose file.