Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wait for postgres container to start #602

Closed
jayfk opened this issue Jun 8, 2016 · 3 comments
Closed

Wait for postgres container to start #602

jayfk opened this issue Jun 8, 2016 · 3 comments
Labels

Comments

@jayfk
Copy link
Collaborator

jayfk commented Jun 8, 2016

Django's runserver relies on a working database connection during startup. If this is not the case runserver fails entirely and the container has to be restarted.

To circumvent that, the runserver call should be wrapped in a function that checks if the postgres database is up and running.

This only affects the development environment. Production is fine.

@rougeth
Copy link

rougeth commented Jun 18, 2016

There's an example on Docker Compose docs of a container waiting for postgres to start, that can be useful: https://docs.docker.com/compose/startup-order/

@anthonysutardja
Copy link

This sounds like something that could be solved with modifying the command in the docker-compose file.

https://github.com/vishnubob/wait-for-it

Maybe placing this file (wait-for-it.sh) in the utilities directory could be useful? The script waits for the host and port to spin up (with a timeout) before exiting. The command in docker-compose would then be changed to the following:

   command: bash -c "./utilities/wait-for-it.sh postgres:5432 && python /app/manage.py runserver_plus 0.0.0.0:8000"

@yashinshekh
Copy link

docker-compose down --volumes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants