1.2 — Docker Setup & Deployment
Docker Setup and Deployment: Creating the Factory Ground
Docker is the foundation of the Automated Growth Empire. It allows you to run complex software like n8n or PostgreSQL in isolated "containers," ensuring your infrastructure is identical across your local laptop, a Karachi co-working space WiFi, and a production VPS in Germany. Once you understand Docker, deploying n8n anywhere takes under 10 minutes.
The Docker Mental Model
Before touching any commands, understand the four core Docker concepts. Everything else builds on these.
| Term | Concept | Industrial Analogy |
|---|---|---|
| Image | The blueprint of the software — a read-only template | The factory schematic (a PDF of the design) |
| Container | A running instance of an image — isolated and ephemeral | The active factory floor (can be stopped, restarted) |
| Volume | Persistent storage that survives container restarts | The warehouse — goods stay even if the floor shuts down |
| Network | How containers communicate with each other | The internal phone and conveyor belt system |
| docker-compose | A YAML file that defines multi-container setups | The master project plan that coordinates all departments |
The Docker Architecture for n8n
Your VPS or Local Machine
├── Docker Engine (Container Runtime)
│ ├── n8n Container (Port 5678)
│ │ ├── n8n application process
│ │ ├── Embedded SQLite database (default)
│ │ └── Workflow execution engine
│ │
│ ├── Volume: n8n_data
│ │ ├── /home/node/.n8n/config (settings)
│ │ ├── /home/node/.n8n/database.sqlite (all workflows + credentials)
│ │ └── /home/node/.n8n/nodes (custom nodes if installed)
│ │
│ └── Network: n8n_default
│ └── Internal DNS: n8n → 172.18.0.2
│
└── Host ports exposed: 5678 → container:5678
The volume is the critical piece. Without it, stopping your container destroys all your workflows. With a named volume, your data persists through restarts, upgrades, and crashes.
The docker-compose.yml for n8n
This is the production-standard file. Save it as docker-compose.yml in a directory like /opt/n8n/ on your VPS:
version: '3.8'
services:
n8n:
image: n8nio/n8n:latest
restart: always
ports:
- "5678:5678"
environment:
- N8N_HOST=automate.yourdomain.com
- N8N_PORT=5678
- N8N_PROTOCOL=https
- NODE_ENV=production
- WEBHOOK_URL=https://automate.yourdomain.com/
- GENERIC_TIMEZONE=Asia/Karachi
- TZ=Asia/Karachi
volumes:
- n8n_data:/home/node/.n8n
networks:
- n8n_network
volumes:
n8n_data:
driver: local
networks:
n8n_network:
driver: bridge
Key fields to understand:
restart: always— container auto-starts on server reboot (critical for 24/7 uptime)GENERIC_TIMEZONE=Asia/Karachi— all scheduled triggers fire in PKT (UTC+5), not UTCWEBHOOK_URL— tells n8n what its public URL is so webhook URLs are generated correctlyn8n_datavolume — your SQLite database and all workflow JSON lives here
Why restart: always Matters
In automation, uptime is revenue. Consider this scenario: your Contabo VPS in Germany receives a scheduled maintenance reboot at 3 AM. Without restart: always, your n8n instance stays down until you SSH in and start it manually — potentially hours later. With restart: always, Docker brings it back up within 30 seconds automatically. For Pakistani clients relying on order processing workflows, those hours of downtime are PKR directly lost.
VPS Selection Guide for Pakistan (2026 Rates)
| Provider | Plan | RAM | Price/month | Best For |
|---|---|---|---|---|
| Contabo VPS S | Standard | 8GB | $7.50 | 1-3 clients, learning |
| Contabo VPS M | Standard | 16GB | $13.50 | 4-10 clients, production |
| DigitalOcean | Basic Droplet | 2GB | $12 | Lowest latency to Southeast Asia |
| Hostinger KVM 2 | VPS | 4GB | $8.99 | Budget option, decent uptime |
| Vultr High Performance | 1 vCPU | 2GB | $12 | Fast NVMe, Singapore node available |
Payment tip for Pakistani developers: Most of these accept PayPal, Wise, or Payoneer. If your local bank card gets rejected (common with Meezan, UBL, Habib cards on foreign sites), use Payoneer or create a Wise virtual card — standard practice in the Karachi freelance community.
Recommended for beginners: Contabo VPS S ($7.50/month). Its Germany location provides good latency to both European and Pakistani traffic. 8GB RAM easily handles 10+ concurrent n8n workflow executions.
Practice Lab: Your First Container
Exercise 1: Install and Verify Docker
# Install Docker Desktop (Windows/Mac) or Docker Engine (Linux)
# After installation, verify:
docker --version
# Expected: Docker version 27.x.x or higher
docker run hello-world
# Expected: "Hello from Docker!" message
Exercise 2: Run Your First Web Container
docker run -d -p 8080:80 nginx
Visit http://localhost:8080 — you are now hosting an Nginx web server in an isolated container. Kill it:
docker stop $(docker ps -q --filter ancestor=nginx)
Exercise 3: Launch n8n with docker-compose
# Create your n8n directory
mkdir -p /opt/n8n && cd /opt/n8n
# Create the docker-compose.yml (paste the content from this lesson)
# Start n8n in the background
docker-compose up -d
# Verify it's running
docker-compose ps
# Expected: n8n Up 0.0.0.0:5678->5678/tcp
# View live logs
docker-compose logs -f n8n
Visit http://localhost:5678 (or your VPS IP:5678). Create your owner account. Your automation factory is live.
Pakistan Case Study: Sana's First VPS
Character: Sana Mirza, 24, graphic designer from Lahore who transitioned into automation freelancing after learning n8n.
The situation: Sana built her first client workflow (a lead-gen pipeline for a Lahore real estate agency) on her local laptop. The client asked: "Can this run 24/7?" Sana had never set up a server before.
What she did:
- Signed up for Contabo VPS S at $7.50/month (paid via Payoneer)
- SSH'd into her Ubuntu 22.04 server for the first time
- Installed Docker with one command:
curl -fsSL https://get.docker.com | sh - Copied her
docker-compose.ymland randocker-compose up -d - n8n was live at her server IP within 8 minutes
The result: Her client's workflow now runs 24/7 in Germany while Sana sleeps in Lahore. She charges PKR 8,000/month maintenance retainer. The VPS costs PKR 2,100/month. Net profit: PKR 5,900/month passive income — from a workflow she built once.
Sana's reflection: "Pehle Docker scary lagta tha. Phir ek baar kar lia toh realize kiya — yeh toh sirf ek command hai. Docker sikhna meri best investment thi."
Key Takeaways
- Docker images are read-only blueprints; containers are running instances — understand this distinction before everything else
- Named volumes (
n8n_data) are mandatory in production — without them, a container restart wipes all your workflows restart: alwaysensures n8n survives VPS reboots and crashes without manual intervention- Set
GENERIC_TIMEZONE=Asia/Karachiso all schedule triggers fire in PKT, not UTC — a 5-hour miscalculation breaks every timed automation - Contabo VPS S ($7.50/month) is the community standard for n8n in Pakistan — 8GB RAM handles 10+ concurrent workflows easily
- Pakistani developers can pay for VPS via Payoneer or Wise when bank cards are rejected on foreign hosting sites
docker-compose up -dis the single command that launches your entire automation factory — master it early- The difference between a self-hosted n8n and a cloud SaaS is the difference between owning your tools and renting them
Recommended Videos and Resources
- Docker Desktop Installation Guide — Official installation for Windows/Mac/Linux
- Type: Documentation
- Link description: Visit docs.docker.com/desktop for your OS
- Docker Compose Explained (n8n Edition) — YouTube walkthrough using docker-compose for n8n specifically
- Type: YouTube
- Link description: Search YouTube for "Docker Compose n8n tutorial"
- n8n Docker Setup on Contabo VPS — Official n8n Docker Compose template
- Type: Documentation
- Link description: Go to docs.n8n.io/hosting/docker
- Understanding Docker Volumes and Persistence — Critical for securing your automation database
- Type: YouTube
- Link description: Search YouTube for "Docker volumes explained"
- Pakistani Developers: VPS + Docker Setup — n8n Community forum with PK-specific threads
- Type: Community Forum
- Link description: Search n8n Community for "VPS Pakistan" or "Contabo setup"
Mini-Challenge
Get Docker running today: Install Docker Desktop, run docker run hello-world, then pull the n8n image with docker pull n8nio/n8n. Launch it with docker-compose using the YAML from this lesson. Access the UI at localhost:5678 and create your owner account. Time yourself — can you go from zero to a running n8n instance in under 15 minutes?
Lesson Summary
Quiz: Docker Setup & Deployment
5 questions to test your understanding. Score 60% or higher to pass.