depends_on with condition: service_healthy is only as good as the health check behind it. While testing database containers for a Docker tutorial, I found that three of the most copied health checks report healthy before the service can actually be used. Your app container starts, its first connection fails, and the logs make it look like a network problem.
Everything below was run on Docker Engine 29.9 with Compose v5.6, using mysql:8.4 , postgres:18 and redis:8-alpine .
1. MySQL: mysqladmin ping -h localhost
This is the health check you'll find in many examples:
healthcheck : test : [ " CMD-SHELL" , " mysqladmin ping -h localhost" ]
Enter fullscreen mode
Exit fullscreen mode
On a fresh volume:
$ docker compose up -d --wait ✔ Container mysql-demo-db-1 Healthy 5.8s
$ docker compose exec db sh -c 'mysql -uroot -p"$MYSQL_ROOT_PASSWORD" -e "SELECT 1"' ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
$ docker compose logs db 2>&1 | grep -E "Temporary server|port:…