Docker untuk Developer Indonesia: Dari Nol Sampai Deploy Production
Docker sudah jadi skill wajib developer modern. Kalau kamu belum paham Docker, kamu ketinggalan. Panduan ini explain Docker dari konsep dasar sampai deploy ke VPS dengan real examples.
Muhamad Putra Aulia Hidayat
Docker: Skill Wajib Developer 2026
Kalau ada satu teknologi yang paling sering bikin developer merasa "harus belajar tapi selalu ditunda", itu adalah Docker.
Artkel ini akan selesaikan itu hari ini.
Kenapa Docker Itu Penting?
Masalah klasik: "Di komputer gue jalan, di server error".
Docker menyelesaikan masalah ini dengan cara mengemas aplikasi beserta semua dependensinya ke dalam satu container yang berjalan identik di mana saja.
Konsep Dasar
Image = Blueprint (template read-only)
Container = Instance yang berjalan dari Image
Dockerfile = Instruksi untuk build Image
Docker Compose = Orkestrasi multiple container
Registry = Tempat simpan Image (Docker Hub, GitHub Registry)
Dockerfile untuk Next.js App
# Build stage
FROM node:20-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
RUN npm run build
# Production stage
FROM node:20-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
# Tambah non-root user untuk security
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
COPY --from=builder /app/public ./public
USER nextjs
EXPOSE 3000
CMD ["node", "server.js"]
Docker Compose untuk Full Stack App
# docker-compose.yml
version: '3.8'
services:
app:
build: .
ports:
- "3000:3000"
environment:
- DATABASE_URL=postgresql://postgres:password@db:5432/myapp
- REDIS_URL=redis://cache:6379
depends_on:
db:
condition: service_healthy
cache:
condition: service_started
restart: unless-stopped
db:
image: postgres:16-alpine
environment:
POSTGRES_DB: myapp
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5
cache:
image: redis:7-alpine
command: redis-server --save 20 1 --loglevel warning
volumes:
- redis_data:/data
nginx:
image: nginx:alpine
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf
- ./ssl:/etc/ssl
depends_on:
- app
volumes:
postgres_data:
redis_data:
Deploy ke VPS
# 1. SSH ke VPS
ssh user@your-vps-ip
# 2. Install Docker
curl -fsSL https://get.docker.com | sh
sudo usermod -aG docker $USER
# 3. Clone repo
git clone https://github.com/yourname/yourapp.git
cd yourapp
# 4. Setup environment
cp .env.example .env
nano .env # Edit nilai-nilainya
# 5. Build dan run
docker compose up -d --build
# 6. Cek status
docker compose ps
docker compose logs -f app
Tips Docker yang Sering Dilupakan
1. Gunakan .dockerignore
node_modules
.git
.env
.next
*.log
README.md
2. Multi-stage build untuk image kecil Tanpa multi-stage, image Next.js bisa 1GB+. Dengan multi-stage bisa di bawah 200MB.
3. Health check selalu Jangan deploy container tanpa health check. Kalau app crash, Docker tidak tahu kecuali ada health check.
4. Jangan simpan secrets di image Gunakan environment variables atau Docker secrets, bukan hardcode di Dockerfile.
Workflow CI/CD dengan Docker
# .github/workflows/deploy.yml
name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build image
run: docker build -t myapp:${{ github.sha }} .
- name: Push to registry
run: |
echo ${{ secrets.REGISTRY_TOKEN }} | docker login ghcr.io -u ${{ github.actor }} --password-stdin
docker push ghcr.io/${{ github.repository }}:${{ github.sha }}
- name: Deploy to VPS
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USER }}
key: ${{ secrets.VPS_SSH_KEY }}
script: |
cd /app
docker compose pull
docker compose up -d
docker system prune -f
Docker skill yang solid akan langsung terasa dampaknya: deployment lebih konsisten, onboarding tim lebih cepat, dan tidak ada lagi drama "works on my machine".
Newsletter Digital Uptime
Tips teknologi & bisnis mingguan
Bergabung dengan 2,500+ subscriber yang mendapatkan insight teknologi, tutorial development, dan tips bisnis digital langsung ke inbox mereka setiap minggu.