Compose로 프로필 사용하기
Compose로 프로필 사용하기 (Using profiles with Compose)
프로필(profiles)은 Compose 파일에 정의된 서비스 그룹을 선택적으로 활성화할 수 있게 해 줘요. 서비스에 프로필을 지정하면 기본적으로 시작되지 않다가, 필요할 때만 활성화돼요.
출처: 문서
본문
서비스에 프로필 지정하기 (Assigning profiles to services)
profiles 속성은 프로필 이름 배열을 가져요:
services:
frontend:
image: frontend
profiles: [frontend]
phpmyadmin:
image: phpmyadmin
depends_on: [db]
profiles: [debug]
backend:
image: backend
db:
image: mysql
frontend와 phpmyadmin은 각각 프로필이 지정되어 있어, 해당 프로필이 활성화될 때만 시작돼요. backend와 db는 프로필이 없어서 항상 활성화되고 자동으로 시작돼요.
특정 프로필 시작하기 (Start specific profiles)
--profile 플래그나 COMPOSE_PROFILES 환경 변수로:
$ docker compose --profile debug up
$ COMPOSE_PROFILES=debug docker compose up
여러 프로필 시작하기 (Start multiple profiles)
여러 프로필을 지정하면 모두 활성화돼요:
$ docker compose --profile frontend --profile debug up
$ COMPOSE_PROFILES=frontend,debug docker compose up
자동 시작 프로필과 의존성 해석 (Auto-starting profiles and dependency resolution)
커맨드 라인에서 프로필이 지정된 서비스를 명시적으로 타깃팅하면 해당 프로필이 자동으로 활성화될 수 있어요. 프로필이 활성화되지 않은 서비스를 다른 서비스가 depends_on으로 의존하면 Compose가 그 프로필을 자동으로 켜서 의존성을 해결해요. 자세한 규칙은 원본 문서를 참고해요.