Day 6 - Docker vs VM: Deep Comparison Analysis

Context: After completing VM deployment (Week 1), returning to Docker with new appreciation


⏱️ Performance Comparison

Deployment Time

| Metric | VM (Automated) | Docker | Speedup | |——–|—————-|——–|———| | Infrastructure | 37 sec (Terraform) | 0 sec (local) | N/A | | Application Start | 60 sec (script) | 7.64 sec | 7.8x faster | | Total (Full Stack) | 1 min 37 sec | 7.64 sec | 12.7x faster |

CPU Usage: 3% (Docker) vs ~15% (VM systemd overhead)


📋 What I Had to Do Manually on VM

1. Environment Setup

VM Process:

# Install Go (2 minutes)
sudo snap install go --classic
go version

# Create application user (1 minute)
sudo useradd -r -s /bin/false appuser
sudo mkdir -p /opt/job-listing
sudo chown appuser:appuser /opt/job-listing

Docker Equivalent:

# Dockerfile (automatic)
FROM golang:1.21-alpine
USER appuser  # Created in image

Time Saved: 3 minutes
Error Potential: High (permissions, paths) → None


2. Application Deployment

VM Process:

# Clone & build (1-2 minutes)
git clone repo
cd job-listing
go build -o main

# Copy files (manual, error-prone)
sudo cp main /opt/job-listing/
sudo cp data.json /opt/job-listing/
sudo cp index.html /opt/job-listing/
sudo chmod +x /opt/job-listing/main

# If you forget ONE file → service crash

Docker Equivalent:

# Dockerfile (guaranteed complete)
COPY . .
RUN go build -o main
# Everything included automatically

Time Saved: 2 minutes
Error Potential: High (missing files) → None


3. Service Management

VM Process:

# Create systemd service file (~5 minutes + debugging)
sudo nano /etc/systemd/system/job-listing.service
# [Unit], [Service], [Install] sections
# WorkingDirectory, ExecStart, User, Group...

# Reload and start
sudo systemctl daemon-reload
sudo systemctl start job-listing
sudo systemctl enable job-listing

# Debug if it fails (status 217/USER, 203/EXEC...)
sudo journalctl -u job-listing -f

Docker Equivalent:

# docker-compose.yml
services:
  app:
    restart: always

Time Saved: 5+ minutes
Error Potential: Very High → None


4. Port Management

VM Issues Encountered:

  • Port 8000 already in use → fuser -k 8000/tcp
  • Multiple instances running → manual cleanup
  • Permission denied on port 80 → need sudo or >1024

Docker Solution:

  • Port mapping: 8000:8000 (isolated)
  • Container restart = automatic cleanup
  • No port conflicts between containers

Time Saved: 2-5 minutes (debugging)


5. Networking

VM Process:

  • Manual firewall rules (Security Groups)
  • iptables configuration
  • Internal service discovery (localhost:5432)

Docker:

services:
  app:
    networks: [app-network]
  postgres:
    networks: [app-network]
# Services communicate by name automatically

Complexity: High → Low


🔍 Configuration Comparison

scripts/deploy

Issues:

  • Fragile (path assumptions)
  • Platform-specific (Ubuntu/systemd)
  • Requires root access
  • Must handle edge cases manually
  • Single-server only

deployments/docker-compose.yml

Advantages:

  • Declarative (what, not how)
  • Platform-agnostic
  • No root required
  • Handles edge cases automatically
  • Multi-server ready

💡 Key Realizations

What Docker Automates That I Struggled With

  1. Dependency Hell: Solved
    • VM: Manual Go installation, version conflicts
    • Docker: Exact version in Dockerfile, reproducible
  2. “Works on My Machine”: Eliminated
    • VM: Different Ubuntu versions, packages
    • Docker: Identical everywhere
  3. Process Management: Simplified
    • VM: systemd complexity, restart policies, logs
    • Docker: restart: always, docker logs
  4. Isolation: Perfect
    • VM: Shared filesystem, ports, users
    • Docker: Complete isolation by default
  5. Cleanup: Easy
    • VM: Manual uninstall, leftover files
    • Docker: docker compose down = clean slate

🎓 What VM Experience Taught Me

Appreciation Points:

  1. Understanding the abstraction:
    • I know what Docker does “under the hood”
    • systemd → Docker’s restart policies
    • Linux users → Container user namespace
    • Ports → Container networking
  2. Debugging skills:
    • Can troubleshoot Docker issues because I understand Linux
    • Know what logs to check
    • Understand process management
  3. Architecture decisions:
    • When to use VMs (regulatory, kernel mods)
    • When to use containers (99% of cases)
    • Why Kubernetes exists (orchestrating many containers)

📊 Final Verdict

Criterion VM Docker Winner
Speed 1m37s 7.6s 🐳 Docker
Simplicity 80 lines bash 45 lines YAML 🐳 Docker
Reproducibility ~80% 100% 🐳 Docker
Error-prone High None 🐳 Docker
Learning Value High Medium 🖥️ VM
Production Ready Complex Simple 🐳 Docker


infra-lab DevOps Pipeline — Lionel Pinheiro Duarte

This site uses Just the Docs, a documentation theme for Jekyll.