What tool can manage Docker container to start in order?

174 Views Asked by At

We're trying to port our system to the containers, currently we try Docker module with Puppet and we face an issue with the order of starting some specific conainers.
We have a web application, MySQL, NginX and then everything connect through HAproxy. Each of them live in their own container.
We start some container before some else, for example the MySQL container must ready before the HAproxy. But HAProxy starts faster than MySQL. HAProxy checks the set TCP connections. Because MySQL is not ready, our application daemons cannots start.Outside, we can't really know going on, because the HAProxy is running, after a while the remaining services running too. ( We can't rely on the pidfile either, because it is created even in a stage when it is not fully started.)
What tool can we use for this case?
Or, what is the better approach?

1

There are 1 best solutions below

0
On BEST ANSWER

The simplest approach that works would be to simply add a retry policy to your container and make sure that if it cannot access the required resource on startup it exits:

docker run -d mysql
docker run -d --restart always --link mysql:mysql nginx start_or_die.sh

The start_or_die.sh script here would first ping mysql for a health check then start nginx:

#!/usr/bin/env bash
set -e
mysql -u root -e 'use mydbname'
nginx -g 'daemon off;'