Docker Compose Wait til dependency container is fully up before launching

后端 未结 2 634
南笙
南笙 2021-02-14 09:55

I\'m working with a docker service using docker-compose, and I have a service that depends on anther.

I\'ve used the depends_on key, but the service with t

2条回答
  •  独厮守ぢ
    2021-02-14 10:23

    I've often found using a wait-for-it bash script much more effective than the built in health check to docker-compose.

    This runs a TCP health check against a given port and waits until this is complete before starting to run a process.

    Sample code:

    version: "2"
    services:
      web:
        build: .
        ports:
          - "80:8000"
        depends_on:
          - "db"
        command: ["./wait-for-it.sh", "db:5432", "--", "python", "app.py"]
      db:
        image: postgres
    

    Here's some docs:

    • https://docs.docker.com/compose/startup-order/
    • https://github.com/vishnubob/wait-for-it

提交回复
热议问题