Assume that you have two docker services/containers. One must be ready to accept connections from the other one. As you have just noticed, I didn’t say “one must be running” because there is different between being “ready to accept connections” and “running”. The depends_on key of docker compose doesn’t always solve the problem because it just checks if the container is running. This is often the case if a service depends on Cassandra, MySQL, RabbitMQ, Elasticsearch like services. They take time to accept connections. To solve such issue, we can use an additional script. This script would periodically ping these services until they are ready to accept connections before actually running the main service.

In this example we have a Go and Cassandra service. Go depends on Cassandra. Cassandra is slow in accepting connections. We will use our script in Go to force it to wait for Cassandra to accept connections first. Once Cassandra says it is ready then we will bring up the Go service.

#cassandra #docker #go

Forcing Go Docker container to wait for Cassandra container
1.50 GEEK