본문 바로가기
Q&A2025년 1월 8일1분 읽기

Docker Compose health check 활용

전
전민규
조회 547댓글 4

Docker Compose에서 health check를 설정하는 방법을 알려주세요.

댓글 4

김김영삼1년 전

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가 완전히 준비된 후에 앱이 시작됩니다.

전전민규(guest)1년 전
health check 엔드포인트(/health)는 어떻게 만드나요?
김김영삼1년 전

간단한 헬스체크 엔드포인트:

// Express
app.get("/health", async (req, res) => {
try {
await db.query("SELECT 1"); // DB 연결 확인
res.json({ status: "ok" });
} catch {
res.status(503).json({ status: "error" });
}
});

DB 연결, 외부 서비스 연결 등을 확인하면 더 정확한 헬스체크가 됩니다.

엄엄태준(guest)1년 전
관리자님 항상 감사합니다. 덕분에 해결됐습니다!
Ctrl+Enter로 등록