Docker Compose: Auto-Restart & Healthcheck Biar Bisa Tidur Nyenyak
Males banget kan lagi enak-enak merem jam 3 pagi, tetangga nge-WA server down gara-gara container mokad diem-diem? Yoi, makanya jangan cuma docker compose up -d terus ditinggal ngopi.
Nih resep singkat biar container lu bandel, otomatis restart kalau teler, dan ngecek kesehatan mandiri.
Snippet Praktis docker-compose.yml
version: '3.8'
services:
web_app:
image: nginx:alpine
container_name: astropaste_app
restart: unless-stopped
ports:
- "80:80"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost/"]
interval: 30s
timeout: 10s
retries: 3
start_period: 10s
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
Catatan Dikit Biar Paham:
restart: unless-stopped: Ini penyelamat mental. Kalau server reboot atau container nge-crash karena OOM, dia bakal otomatis bangun sendiri. Kecuali lu matiin manual.healthcheck: Docker nggak cuma tau container "nyala", tapi tau juga aplikasinya "beneran hidup" apa cuma mangap doang.max-size: Log Docker itu demen banget makan storage VPS sampe abis. Batasin biar disk lu nggak megap-megap.
Udah, pasang itu buruan. Kopi mana kopi, mata udah 5 watt nih.