2025-05-11 13:34:43
【調べ中】Docker の compose.yaml で作ってるWEBサービスでhttpコンテナが1つでも起動してたらロードバランサーコンテナを起動させたい
やりたいこと
これだとhttpd-1コンテナとhttpd-2コンテナの両方が起動していないとha_proxyコンテナが起動しない。
services:
ha_proxy:
container_name: ha_proxy
build:
context: ./docker
dockerfile: ./dev-Dockerfile-HAProxy
ports:
- "80:80"
depends_on:
httpd-1:
condition: service_healthy
restart: true
httpd-2:
condition: service_healthy
restart: true
httpd-1:
container_name: httpd-1
build:
context: ./docker
dockerfile: ./dev-Dockerfile-httpd
depends_on:
- phpfpm-1
environment:
PHP_FPM_CONTAINER: "phpfpm-1"
volumes:
- type: bind
source: www.app.com/public/assets/
target: /var/www/assets.app.com/public/assets/
healthcheck:
test: ["CMD", "curl", "-f", "http://www.app.internal"]
interval: 5s
timeout: 10s
retries: 5
httpd-2:
container_name: httpd-2
build:
context: ./docker
dockerfile: ./dev-Dockerfile-httpd
depends_on:
- phpfpm-2
environment:
PHP_FPM_CONTAINER: "phpfpm-2"
volumes:
- type: bind
source: www.app.com/public/assets/
target: /var/www/assets.app.com/public/assets/
healthcheck:
test: ["CMD", "curl", "-f", "http://www.app.internal"]
interval: 5s
timeout: 10s
retries: 5
httpd-1コンテナまたは、httpd-2コンテナの1つが起動していたらha_proxyコンテナを起動させたい。「entrypoint」なるものを使えば実現できそうなので調べ中です。