我有一个应用程序,使用Docker SDK for Python和运行容器与Flask应用程序。我正在使用以下代码运行容器:
import docker
client = docker.from_env()
client.containers.run("container-name", ports={50: 8080}, detach=True}
由于容器被分离,当容器没有时间加载时,下一行变成了execute。因此,如果我尝试发出请求:
import requests
res = requests.get("localhost:8080")
我会得到一个错误。
当然,我可以使用这样的构造:
while True:
try:
res = requests.get("localhost:8080")
break
except:
print("Retry to connect")
但这对我不好。有没有其他方法可以检查容器是否已准备好接受请求?
https://stackoverflow.com/questions/55172616
复制相似问题