I am using postgresql with django in my project. i've got them in different containers and the problem is that i need to wait for postgres before running django. At this time i am doing it with sleep 5
in command.sh file for django container. I also found that netcat can do the trick but i would prefer way without additional packages. curl and wget can't do this because they do not support postgres protocol.
Is there a way to do it?
相关问题
- Docker task in Azure devops won't accept "$(pw
- Unable to run mariadb when mount volume
- Django distinct is not working
- PostgreSQL: left outer join syntax
- Unspecified error (0x80004005) while running a Doc
The simplest solution is a short bash script:
This will successfully wait for Postgres to start. (Specifically line 6). Just replace
npm start
with whatever command you'd like to happen after Postgres has started.If you have
psql
you could simply add the following code to you .sh file:Maybe you could use docker compose to manage your containers.
Here is the documentation.
In its yaml file, you can set the
links
properties to express dependency between services. Then, the service will startup as you wish.Problem with your solution tiziano is that curl is not installed by default and i wanted to avoid installing additional stuff. Anyway i did what bereal said. Here is the script if anyone would need it.
wait-for-it small wrapper scripts which you can include in your application’s image to poll a given host and port until it’s accepting TCP connections.
can be cloned in Dockerfile by below command
docker-compose.yml