Apply for Free VPS

Run an application with Docker Compose

Updated 27 Nov 2026 docker compose

Define services in one file, limit memory and keep data in volumes.

First install Docker.

compose.yaml

services:
  web:
    image: nginx:stable-alpine
    ports:
      - "20002:80"
    restart: unless-stopped
    mem_limit: 128m
    logging:
      driver: json-file
      options: { max-size: "10m", max-file: "3" }
  db:
    image: postgres:16-alpine
    environment:
      POSTGRES_PASSWORD: ${DB_PASSWORD}
    volumes:
      - dbdata:/var/lib/postgresql/data
    restart: unless-stopped
    mem_limit: 384m
volumes:
  dbdata:

Put DB_PASSWORD=... in a file named .env beside it, run chmod 600 .env, and do not commit it.

Run

docker compose up -d
docker compose ps
docker compose logs -f --tail=50

Update

docker compose pull && docker compose up -d
docker image prune -f

Remember

Published ports bypass ufw. The database above has no ports, so only other services can reach it. Back up data with a database dump, not by copying the volume while it is running.

Was this helpful?

Report outdated or incorrect information