depends_on doesn't wait for another service in docker-compose 1.22.0

前端 未结 2 774
醉话见心
醉话见心 2021-01-05 18:43

My current docker-compose.yml -

# This docker-compose file uses \'.env\' file present in the current directory, 
# for database credentials.         


        
2条回答
  •  一整个雨季
    2021-01-05 19:11

    Note that depends_on only waits for the other container to be up, but not for the process it is running to start. The thing that could probably be happening in your case is that you are trying to connect to the postgres process on its specified port while it's still getting started.

    There are two ways you can tackle such a scenario -

    1. Specify some sort of restart clause for your python-app container - You are probably seeing your python-app container in failed state and so you have posted this question. restart: on-failure:10 in the docker-compose.yml for your python-app service will restart your container up to 10 times in case it fails connecting to the postgres container. This will ensure that you would have given it enough time before the postgres container is up and running...the process that is.

    2. Use an external tool like dockerize that allows you to wait on other services before starting up the container. This essentially gives you the behavior you desire with depends_on.

提交回复
热议问题