DevOps14 min read•Updated November 2026

How to Deploy Docker Containers on a VPS Server

Quick answer

To run containers on a VPS, install Docker Engine and the Compose plugin from Docker's official apt repository, describe your stack in a compose.yaml, and start it with docker compose up -d. Keep databases unpublished and bind app ports to 127.0.0.1 behind Nginx, because Docker's port rules bypass UFW. Store data in named volumes, set restart: unless-stopped, cap container logs, and update with docker compose pull && docker compose up -d.

Docker turns "it works on my machine" into "it works on the server": the same image runs in development and production, dependencies are isolated, and a whole stack starts with one command. A VPS is a natural home for Docker because you get root access, a stable public IP and dedicated resources. This guide installs Docker the supported way, deploys a realistic multi-container application with Docker Compose, and covers the production details that tutorials usually skip.

Step 1: Install Docker Engine

Use Docker's own repository rather than the docker.io package from Ubuntu, so you get current releases and the Compose plugin. On Ubuntu:

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
sudo docker run --rm hello-world

On Debian, replace ubuntu with debian in both URLs. Check Docker's installation documentation if these steps change.

The docker group: adding your user with sudo usermod -aG docker $USER lets you run Docker without sudo. Be aware that membership of the docker group is effectively root access, because a user can mount the host filesystem into a container. Only add trusted administrators.

Step 2: Describe the Stack with Docker Compose

A typical web application with PostgreSQL and Redis, in /opt/myapp/compose.yaml:

services:
  app:
    image: ghcr.io/your-org/myapp:1.4.2
    restart: unless-stopped
    env_file: .env
    ports:
      - "127.0.0.1:8000:8000"   # only reachable from the host (Nginx)
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_started

  db:
    image: postgres:16
    restart: unless-stopped
    environment:
      POSTGRES_DB: myapp
      POSTGRES_USER: myapp
      POSTGRES_PASSWORD_FILE: /run/secrets/db_password
    secrets:
      - db_password
    volumes:
      - pgdata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U myapp -d myapp"]
      interval: 10s
      timeout: 5s
      retries: 5
    # no "ports:" - the database is only reachable on the internal network

  redis:
    image: redis:7
    restart: unless-stopped
    command: ["redis-server", "--appendonly", "yes"]
    volumes:
      - redisdata:/data

volumes:
  pgdata:
  redisdata:

secrets:
  db_password:
    file: ./secrets/db_password.txt
cd /opt/myapp
mkdir -p secrets && openssl rand -base64 32 > secrets/db_password.txt
chmod 600 secrets/db_password.txt .env
docker compose up -d
docker compose ps
docker compose logs -f app

Key points in this file:

  • Pinned image tags (myapp:1.4.2, postgres:16) instead of latest, so a restart never silently upgrades a database.
  • Containers reach each other by service name (the app connects to host db, port 5432) over the project's private network. The database has no published port at all.
  • Named volumes keep data when containers are recreated.
  • Health checks make the app wait until the database actually accepts connections.

Step 3: Understand the UFW Bypass

Docker manages its own iptables rules for published ports, and they are evaluated before UFW's rules. A service published as "5432:5432" is reachable from the whole internet even when UFW has no rule for 5432. This catches many people out.

  • Bind published ports to localhost ("127.0.0.1:8000:8000"), as above.
  • Do not publish internal services such as databases and caches.
  • If you must restrict a public container port by source IP, add rules to the DOCKER-USER iptables chain.
  • Verify from outside with a port scan after every change.

Our UFW guide covers the host firewall side.

Step 4: Put Nginx and HTTPS in Front

Run Nginx on the host and proxy to the container's localhost port:

server {
    listen 80;
    server_name app.example.com;
    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Then add a certificate with sudo certbot --nginx -d app.example.com (see our Let's Encrypt guide). Running a reverse proxy such as Traefik or Caddy as a container is a valid alternative that can issue certificates automatically; pick one approach and use it consistently.

Step 5: Cap Container Logs

The default json-file log driver keeps logs forever, and a chatty container can fill the disk. Set a global limit in /etc/docker/daemon.json:

{
  "log-driver": "local",
  "log-opts": {
    "max-size": "10m",
    "max-file": "3"
  }
}
sudo systemctl restart docker

The new defaults apply to containers created afterwards, so recreate existing ones with docker compose up -d --force-recreate.

Step 6: Set Resource Limits

Without limits, one leaking container can starve the rest of the server. Add limits per service:

  app:
    deploy:
      resources:
        limits:
          cpus: "1.5"
          memory: 1g

Docker Compose applies deploy.resources.limits when you run docker compose up. Check actual usage with docker stats before choosing values. A small swap file on the host is still a useful safety net; see our swap guide.

Step 7: Update Safely

cd /opt/myapp
# edit the image tag in compose.yaml, then:
docker compose pull
docker compose up -d
docker compose ps
docker image prune -f

Compose only recreates containers whose image or configuration changed. For database major-version upgrades (for example PostgreSQL 16 to 17), do not just change the tag: the data directory format changes, so dump and restore, or use pg_upgrade.

Step 8: Back Up Volumes

Back up databases with their own tools rather than copying live data files:

docker compose exec -T db pg_dump -U myapp myapp | gzip > /backups/myapp-$(date +%F).sql.gz

For other volumes, archive them from a temporary container:

docker run --rm -v myapp_redisdata:/data -v /backups:/backup alpine \
  tar czf /backup/redisdata-$(date +%F).tgz -C /data .

Compose prefixes volume names with the project name, so check the real names with docker volume ls. Copy backups off the server and test a restore.

Housekeeping Commands

TaskCommand
See running containersdocker compose ps / docker ps
Live resource usedocker stats
Disk used by Dockerdocker system df
Remove unused imagesdocker image prune -a (removes images not used by any container)
Shell into a containerdocker compose exec app sh
Restart one servicedocker compose restart app

Avoid docker system prune --volumes on production hosts: it deletes unused volumes, which may contain data from a stopped stack.

SkyRainCloud Plans for This Workload

Docker adds little overhead of its own; size the server for the containers you run. A web app with a database and Redis fits 2 vCores / 8 GB. Multi-service stacks, CI builds and several projects on one host are where the 4–8 vCore AMD EPYC plans pay off.

AMD EPYC 7C13 VPS

Dedicated KVM vCores on AMD EPYC 7C13 (up to 3.70 GHz) with DDR4 ECC memory, NVMe SSD and an unmetered 1 Gbps port.

PlanvCoresRAMStorageNetworkPriceGood forBuy
VPS 1 — AMD28 GB DDR4 ECC40 GB NVMe SSD1 Gbps, unmetered₹649/monthWebsites, small APIs, bots, staging and VPN serversOrder
VPS 2 — AMD416 GB DDR4 ECC80 GB NVMe SSD1 Gbps, unmetered₹1,299/monthWooCommerce, Node.js/Python backends, Docker Compose stacks, CI runnersOrder
VPS 3 — AMD832 GB DDR4 ECC150 GB NVMe SSD1 Gbps, unmetered₹2,499/monthProduction databases, high-traffic sites, multi-container appsOrder
VPS 4 — AMD1664 GB DDR4 ECC250 GB NVMe SSD1 Gbps, unmetered₹4,899/monthLarge production workloads, SaaS platforms, analytics, in-memory cachesOrder

Intel Xeon Platinum 8269CY VPS

KVM VPS on Intel Xeon Platinum 8269CY (up to 3.80 GHz Turbo) with DDR4 ECC memory, NVMe SSD, full root access and an unmetered 1 Gbps port.

PlanvCoresRAMStorageNetworkPriceGood forBuy
VPS 1 — Intel28 GB DDR4 ECC40 GB NVMe SSD1 Gbps, unmetered₹649/monthBusiness websites, small apps, scheduled jobs and botsOrder
VPS 2 — Intel416 GB DDR4 ECC80 GB NVMe SSD1 Gbps, unmetered₹1,169/monthBusiness software, mid-size databases, several sites on one serverCheck stock
VPS 3 — Intel832 GB DDR4 ECC150 GB NVMe SSD1 Gbps, unmetered₹2,249/monthERP/CRM stacks, heavier databases, multiple production appsCheck stock
VPS 4 — Intel1664 GB DDR4 ECC250 GB NVMe SSD1 Gbps, unmetered₹4,299/monthHigh-memory workloads and consolidated production serversCheck stock

Prices are monthly in INR as listed on the SkyRainCloud store (verified 2026-11-14). Stock and final pricing are shown on the product page at checkout.

Troubleshooting

SymptomCause and fix
Container keeps restartingdocker compose logs app; usually a missing environment variable or failed database connection
App cannot reach the databaseUse the service name (db) as the host, not localhost; inside a container, localhost is the container itself
Port reachable despite UFWPublished without 127.0.0.1:; see Step 3
Disk fulldocker system df; prune old images and cap logs
Data lost after recreateData was written inside the container instead of a volume
"permission denied" on docker.sockUser not in the docker group (log out and back in after adding)

Frequently Asked Questions

Should I install Docker from Ubuntu's repository or Docker's?
Docker's official repository gives you current Docker Engine releases plus the Compose and Buildx plugins. Ubuntu's docker.io package works but usually lags behind.
What is the difference between docker-compose and docker compose?
docker-compose was the old standalone Python tool (Compose v1), which is no longer supported. docker compose is the current Compose v2 plugin installed with Docker Engine.
Why can people reach my container even though UFW blocks the port?
Docker inserts its own iptables rules that run before UFW. Bind published ports to 127.0.0.1, avoid publishing internal services, or filter in the DOCKER-USER chain.
How much RAM do I need to run Docker on a VPS?
Docker itself needs very little. Add up the memory your containers use (check with docker stats) and leave headroom. A web app, PostgreSQL and Redis typically fit in 8 GB.
How do I keep data when containers are recreated?
Store it in named volumes or bind mounts, never only inside the container's writable layer. Back up databases with their dump tools.
How do I restart containers automatically after a reboot?
Set restart: unless-stopped (or always) on each service and make sure the Docker service is enabled: sudo systemctl enable docker.
Is it safe to add my user to the docker group?
It is convenient, but docker group membership is equivalent to root on that host. Only add trusted administrators, or use rootless Docker for stricter isolation.
How do I update a container to a new version?
Change the image tag in compose.yaml, then run docker compose pull and docker compose up -d. Compose recreates only the changed services.
Can I run Docker on any VPS?
You need full KVM virtualization and root access. Container-based VPS types such as OpenVZ often cannot run Docker. SkyRainCloud VPS plans are KVM with full root access.
Which SkyRainCloud plan should I use for Docker?
Start with 2 vCores / 8 GB for one application stack. Choose the 4 vCore / 16 GB tier for several stacks or CI builds, and 8 vCores / 32 GB for busy multi-service platforms. AMD EPYC plans suit highly parallel container workloads.
Instant UPI • ₹649/mo
Fast KVM Cloud Provisioning