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 oflatest, 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-USERiptables 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
| Task | Command |
|---|---|
| See running containers | docker compose ps / docker ps |
| Live resource use | docker stats |
| Disk used by Docker | docker system df |
| Remove unused images | docker image prune -a (removes images not used by any container) |
| Shell into a container | docker compose exec app sh |
| Restart one service | docker 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.
| Plan | vCores | RAM | Storage | Network | Price | Good for | Buy |
|---|---|---|---|---|---|---|---|
| VPS 1 — AMD | 2 | 8 GB DDR4 ECC | 40 GB NVMe SSD | 1 Gbps, unmetered | ₹649/month | Websites, small APIs, bots, staging and VPN servers | Order |
| VPS 2 — AMD | 4 | 16 GB DDR4 ECC | 80 GB NVMe SSD | 1 Gbps, unmetered | ₹1,299/month | WooCommerce, Node.js/Python backends, Docker Compose stacks, CI runners | Order |
| VPS 3 — AMD | 8 | 32 GB DDR4 ECC | 150 GB NVMe SSD | 1 Gbps, unmetered | ₹2,499/month | Production databases, high-traffic sites, multi-container apps | Order |
| VPS 4 — AMD | 16 | 64 GB DDR4 ECC | 250 GB NVMe SSD | 1 Gbps, unmetered | ₹4,899/month | Large production workloads, SaaS platforms, analytics, in-memory caches | Order |
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.
| Plan | vCores | RAM | Storage | Network | Price | Good for | Buy |
|---|---|---|---|---|---|---|---|
| VPS 1 — Intel | 2 | 8 GB DDR4 ECC | 40 GB NVMe SSD | 1 Gbps, unmetered | ₹649/month | Business websites, small apps, scheduled jobs and bots | Order |
| VPS 2 — Intel | 4 | 16 GB DDR4 ECC | 80 GB NVMe SSD | 1 Gbps, unmetered | ₹1,169/month | Business software, mid-size databases, several sites on one server | Check stock |
| VPS 3 — Intel | 8 | 32 GB DDR4 ECC | 150 GB NVMe SSD | 1 Gbps, unmetered | ₹2,249/month | ERP/CRM stacks, heavier databases, multiple production apps | Check stock |
| VPS 4 — Intel | 16 | 64 GB DDR4 ECC | 250 GB NVMe SSD | 1 Gbps, unmetered | ₹4,299/month | High-memory workloads and consolidated production servers | Check 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
| Symptom | Cause and fix |
|---|---|
| Container keeps restarting | docker compose logs app; usually a missing environment variable or failed database connection |
| App cannot reach the database | Use the service name (db) as the host, not localhost; inside a container, localhost is the container itself |
| Port reachable despite UFW | Published without 127.0.0.1:; see Step 3 |
| Disk full | docker system df; prune old images and cap logs |
| Data lost after recreate | Data was written inside the container instead of a volume |
| "permission denied" on docker.sock | User 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.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?
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 stats) and leave headroom. A web app, PostgreSQL and Redis typically fit in 8 GB.How do I keep data when containers are recreated?
How do I restart containers automatically after a reboot?
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?
How do I update a container to a new version?
compose.yaml, then run docker compose pull and docker compose up -d. Compose recreates only the changed services.