I do not think that there is a standard way to solve this problem, but this is a known problem, and some people have acceptable workarounds.
There is a suggestion in the Docker issue tracker that you do not consider the container as running until it listens on open ports. However, this is most likely not to be accepted due to other problems that it would create elsewhere. There is a drawing on the same topic.
A simple solution is to make a dream, as @jcortejoso says. Example from http://blog.chmouel.com/2014/11/04/avoiding-race-conditions-between-containers-with-docker-and-fig/ :
function check_up() { service=$1 host=$2 port=$3 max=13 # 1 minute counter=1 while true;do python -c "import socket;s = socket.socket(socket.AF_INET, socket.SOCK_STREAM);s.connect(('$host', $port))" \ >/dev/null 2>/dev/null && break || \ echo "Waiting that $service on ${host}:${port} is started (sleeping for 5)" if [[ ${counter} == ${max} ]];then echo "Could not connect to ${service} after some time" echo "Investigate locally the logs with fig logs" exit 1 fi sleep 5 (( counter++ )) done }
And then use check_up "DB Server" ${RABBITMQ_PORT_5672_TCP_ADDR} 5672 before starting the application server, as described in the link above.
Another option is to use docker-wait . In fig.yml .
rabbitmq: image: dockerfile/rabbitmq:latest mongodb: image: mongo rabbitmqready: image: aanand/wait links: - rabbitmq app: build: . command: python /code/app/main.py links: - rabbitmqready - mongodb volumes: - .:/code
source share