I am trying to start one container after the MySQL one is initialized.
This was not an issue in docker-compose v2.1 In the version 3 of docker-compose the depends-on doesn't have the condition statement anymore.
My current setup looks like this:
test:
image: php:7.2
container_name: second
restart: on-failure
depends_on:
- mysql-test
mysql-test:
image: mysql:5.7
container_name: first
environment:
MYSQL_ROOT_PASSWORD: secret
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-psecret", "-h", "localhost"]
timeout: 30s
retries: 10
Of course, running docker-compose up and then executing script in the PHP container that is trying to connect to the database results in SQLSTATE[HY000] [2002] Connection refused since MySQL container is not ready yet.
Is there a recommended approach to this problem in docker-compose version 3 or any kind of a workaround?