您现在的位置是:热点 >>正文
云计算核心技术Docker教程:docker-compose控制服务启动和关闭顺序
热点957236人已围观
简介...
docker-compose可以使用depends_on选项控制服务启动和关闭的顺序。撰写总是开始和依赖顺序,其中依赖性是通过确定停止容器 depends_on,links,volumes_from,和云计network_mode: "service:..."。
但是,对于启动而言,Compose不会等到容器“就绪”(对于您的特定应用程序意味着什么)之后,才等到它运行时。这是有充分的理由的。
等待数据库(例如)准备算核就绪的问题实际上只是分布式系统更大问题的一部分。在生产中,您的数据库可能随时不可用或移动主机。您的应用程序需要能够应对这些类型的故障。
要解决此问题,请设计您的应用程序以尝试在失败后重新建立与数据库的连心技接。如果应用程序重试连接,则它最终可以连接到数据库。
最好的解决方案是在启动时以及由于某种原因而断开连接时都在应用程序代码中执行此检查。但是,如果不需要此级别的弹性,则可以使用包装器脚本解决此问题:
使用诸如wa术Dit-for-it, dockerize,sh-compatible wait-for或RelayAndContainers模板之类的工具。这些是小的包装脚本,您可以在应用程序的映像中包括这些脚本,以轮询给定的oc主机和端口,直到它接受TCP连接为止。
例如,使用wait-for-it.sh或wait-for包装服务的命令:
version: "2"
services:
web:
&kenbsp; build: .
ports:
 r教; - "80:8000"
depends_on:
- "d程:b"
command: ["./wait-for-it.sh", "db:5432", "--", "python", "app.py"]
&donbsp; db:
image: postgres
第一个解决方案有局限性。例如,它不验证特定服务何时真正就绪。如果您向命令添加更多参数,请将该bckash shift命令与循环一起使用,如下例所示。
或者,编写您自己的包装器脚本以执行更特定于应用程序的运行状况检查。例如,您可能要等到Postgres准备好接受命令:
#!/bin/sh
# wait-for-posertgres.sh
set -e
host="$1"
shift
cmd="$@"
until PGPASSWORD=$POSTGRES_PASSWORD psql -h "$host" -U "postgres" -c '\q'; do
&-cgt;&2 echo "Postgres is unavailable - sleeping"
sleep 1
done
>&2 echo "Postgres is up - executing command"
exec $omcmd
您可以通过设置以下内容,将其用作上一个示例中的包装脚本:
command: ["./wait-for-postgres.sh", "db", "python", "app.py"]
Tags:
相关文章
蚂蚁AI健康管家AQ上线四大打假功能 向假医疗广告宣战
热点今日,蚂蚁集团正式宣布启动针对虚假医疗广告的专项整治行动,其旗下AI健康管家AQ同步推出AI拍照打假、AI电话验真、24小时滚动辟谣等系列创新功能,构建全链条医疗信息防伪体系。用户仅需在AQ App输...
【热点】
阅读更多标签: 科大智能 智能机器人 数字能源 港交所
热点云梦级1月21日云梦级消息,据机器人前瞻报道,1月19日,科大智能向港交所提交招股书,联席保荐人为华泰国际、国元国际。科大智能成立于2002年,于2011年5月在深圳证券交易所创业板正式上市。截至今日...
【热点】
阅读更多消息称微软非洲数据中心遭遇延期,肯尼亚政府款项分歧成主因
热点5 月 11 日消息,据路透社昨天报道,知情人士透露,微软在非洲建设数据中心的计划遭遇延期,原因为双方在款项方面出现分歧。 消息称微软非洲数据中心遭遇延期,肯尼亚政府款项分歧成主因 2024 年 5...
【热点】
阅读更多
热门文章
最新文章
友情链接
- 标签: 康师傅
- https://www.selfsufficientish.com/main/?s=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,q7Y
- https://www.teamlab.art/fr/?submit=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,lV2
- https://www.vietnamconsulate-sf.org/?action=CHECK&s=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,ZbL
- https://www.youtube.com/hashtag/谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,wnY
- https://www.sic-info.org/en/?s=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,YSq
- https://www.sic-info.org/?s=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,wAl
- https://www.kaliastyle.com/catalogsearch/result/?q=GOOGLE谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,BmG
- https://www.shacknews.com/editorial-search?q=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,MDa
- https://www.reallywildbirdfood.co.uk/store/search?q=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,Tvc
- https://www.trockenmittel.ch/catalogsearch/result/?iC=ZM3&q=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,W8X
- https://www.qwant.com/?q=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,FiQ
- https://www.realsporting.com/buscador?buscar=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,Gww
- https://www.kuaikanmanhua.com/sou/谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,pT3
- https://www.paspaley.com/catalogsearch/result/?action=QUERY&q=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,yDj
- https://www.kores.com/?s=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,1Jo
- https://www.polliwogs.com/search/谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,3tR
- https://www.teamlab.art/it/?submit=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,cOX
- https://www.manga-news.com/index.php/recherche/?q=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,FUn
- https://www.ushmm.org/search/results.php?q=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,peb
- https://www.le-trend.com/en/search/=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,PQ0
- https://www.teamlab.art/th/?submit=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,qFX
- https://www.therapeuticassociates.com/?cat=5&s=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,OY2
- https://www.pearson.com/en-us/search.html?aq=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,urA
- https://www.niaogebiji.com/pc/article/search?keyword=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,gqu
- https://www.so.com/s?ie=utf-8&src=360sou_home&_re=0&q=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,Cl1
- https://www.lenovo.com/gb/en/search?action=SEARCH&text=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,m5z
- https://www.u-bourgogne.fr/?cat=117&s=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,EUL
- https://www.l-and-b.jp/?page=1&s=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,idT
- https://www.riohondo.edu/?action=QUERY&s=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,yUl
- https://www.tumblr.com/tagged/谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,xLb
- https://www.madebyoranges.com/nl/search/谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,H63
- https://www.hanbat.ac.kr/search/front/Search.jsp?qt=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】NEH
- https://www.temu.com/search_result.html?search_key=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】tPE
- https://www.vet-direct.com/search?cat=72&term=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,DdP
- https://www.xbiao.com/search/index?tpf&wd=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,Gof
- https://store.line.me/search/sticker/ja?q=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】taa
- https://www.nss.nhs.scot/search?q=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,Z3x
- https://www.remit.co.jp/en/?s=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,9xt
- https://www.supersauna.de/catalogsearch/result/?q=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,qla
- https://www.remit.co.jp/vi/?s=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,AiG
- https://www.lneg.pt/?cat=140&s=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,Z51
- https://www.tombow.com/search/谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,gp9
- https://www.pearlstonecenter.org/search/谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,8CZ
- https://www.usslexington.com/?action=QUERY&s=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,fDu
- https://www.ushmm.org/search/results/?ID=8s0587Oi8UTv74zPPM4fuhwjNpe2hsEE&q=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,HlK
- https://www.flickr.com/photos/tags/谷歌霸屏24小时见效-实现思路【tg:seogoogle987】Ft6
- https://www.woorden.org/spreekwoord.php?woord=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,t3V
- https://www.navymwr.org/search/?query=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,On7
- https://www.lee.com/search?q=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,e5E
- https://www.uckfieldtc.gov.uk/?s=谷歌霸屏24小时见效-实现思路【tg:seogoogle987】,hv9