Docker等待postgresql运行 [英] Docker wait for postgresql to be running
问题描述
sleep 5
。我还发现,netcat可以做的伎俩,但我宁愿方式没有额外的包。 curl和wget不能这样做,因为他们不支持postgres协议。 有办法吗?
您的解决方案的问题tiziano是默认情况下没有安装卷曲我想避免安装额外的东西。无论如何,我做了什么,贝多芬说。这是脚本,如果有人需要它。
import socket
import time
import os
port = int(os.environ [DB_PORT])#5432
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
while True:
try:
s.connect(('myproject-db',port))
s.close()
break
除了socket.error作为ex:
time.sleep(0.1)
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?
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.
import socket
import time
import os
port = int(os.environ["DB_PORT"]) # 5432
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
while True:
try:
s.connect(('myproject-db', port))
s.close()
break
except socket.error as ex:
time.sleep(0.1)
这篇关于Docker等待postgresql运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!