Wait-for-it helps overcome limitations with depends_on in docker-compose by staggering various docker container runs.
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.