Wait-for-it + Docker Compose

Krishna Regmi
May 14 · 2 min read

Docker compose is a very useful tool that allows you to deploy multiple docker images together. Below is an example

  • Database (eg Postgres, Mongo etc)
  • Backend (eg API service)
  • Client (eg Nginx )

In most cases you will require one service to be up before you can run another. Docker-compose provides you a helpful tag called depends_on , which ensures that one container runs before the other. Lets see an example of this:

However, in our example, backend might take 1 second to run, and postgres that it depends on being available might take 10 seconds. Docker-compose’s depends_on will run the containers in sequence, but docker-compose has no way of knowing when the postgres service is actually ready to receive requests.

In these types of situations it’s helpful to use a wait-for-it. https://github.com/vishnubob/wait-for-it

Its a helpful tool that lets you wait for another service to be ready. Example usage is as follows:

I hope this was helpful. Please see references for detailed usage.

References:

Krishna Regmi

Written by

A tech-savvy creator type — leading change through data-driven decisions, and customer-first mentality.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade