I am trying to make sure that my app container does not run migrations / start until the db container is started and READY TO accept connections.
So I decided to use
If you can change the container to wait for mysql to be ready do it.
If you don't have the control of the container that you want to connect the database to, you can try to wait for the specific port.
For that purpose, I'm using a small script to wait for a specific port exposed by another container.
In this example, myserver will wait for port 3306 of mydb container to be reachable.
# Your database
mydb:
image: mysql
ports:
- "3306:3306"
volumes:
- yourDataDir:/var/lib/mysql
# Your server
myserver:
image: myserver
ports:
- "....:...."
entrypoint: ./wait-for-it.sh mydb:3306 -- ./yourEntryPoint.sh
You can find the script wait-for-it documentation here