Docker Compose에서 health check를 설정하는 방법을 알려주세요.
Docker Compose health check:
services: db: image: postgres:16 healthcheck: test: ["CMD-SHELL", "pg_isready -U postgres"] interval: 10s timeout: 5s retries: 5 environment: POSTGRES_PASSWORD: pass app: build: . depends_on: db: condition: service_healthy healthcheck: test: ["CMD", "curl", "-f", "http://localhost:3000/health"] interval: 30s timeout: 10s retries: 3
condition: service_healthy로 DB가 완전히 준비된 후에 앱이 시작됩니다.
condition: service_healthy
간단한 헬스체크 엔드포인트:
// Expressapp.get("/health", async (req, res) => { try { await db.query("SELECT 1"); // DB 연결 확인 res.json({ status: "ok" }); } catch { res.status(503).json({ status: "error" }); }});
DB 연결, 외부 서비스 연결 등을 확인하면 더 정확한 헬스체크가 됩니다.
댓글 4
Docker Compose health check:
condition: service_healthy로 DB가 완전히 준비된 후에 앱이 시작됩니다.간단한 헬스체크 엔드포인트:
DB 연결, 외부 서비스 연결 등을 확인하면 더 정확한 헬스체크가 됩니다.