您现在的位置是:热点 >>正文
云计算核心技术Docker教程:docker-compose控制服务启动和关闭顺序
热点782068人已围观
简介...
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:
&nbkesp; build: .
ports:
&r教nbsp; - "80:8000"
depends_on:
&n程:bsp; - "db"
command: ["./wait-for-it.sh", "db:5432", "--", "python", "app.py"]
&ndobsp; db:
image: postgres
第一个解决方案有局限性。例如,它不验证特定服务何时真正就绪。如果您向命令添加更ck多参数,请将该bash shift命令与循环一起使用,如下例所示。
或者,编写您自己的包装器脚本以执行更特定于应用程序的运行状况检查。例如,您可能要等到Postgres准备好接受命令:
#!/bin/sh
# werait-for-postgres.sh
set -e
host="$1"
shift
cmd="$@"
until PGPASSWORD=$POSTGRES_PASSWORD psql -h "$host" -U "postgr-ces" -c '\q'; do
>&2 echo "Postgres is unavailable - sleeping"
sleep 1
done
>&2 echo "Postgres is up - executiomng command"
exec $cmd
您可以通过设置以下内容,将其用作上一个示例中的包装脚本:
command: ["./wait-for-postgres.sh", "db", "python", "app.ppoy"]
Tags:
相关文章
特朗普改口盛赞 Anthropic,五角大楼黑名单风波有望反转
热点美国政商界关于人工智能的安全博弈出现戏剧性转折。总统特朗普近日在公开场合对 Anthropic 公司表示肯定,称其正在“好转”,并表现出与其达成合作的积极意愿。这一表态为这家曾被五角大楼列入黑名单的...
【热点】
阅读更多英伟达 CEO 黄仁勋确认投资马斯克初创公司 xAI
热点近日,英伟达首席执行官黄仁勋在一次采访中确认,英伟达已经对埃隆・马斯克的新创公司 xAI 进行了投资。黄仁勋表示,他对 xAI 正在进行的融资情况感到非常兴奋,同时表达了希望参与马斯克所涉足的几乎所有...
【热点】
阅读更多标签: 元保 YB 财报 保险科技
热点云梦级12月3日云梦级消息,元保(NASDAQ:YB)于12月3日发布了2025年第三季度财报。 财报数据显示,元保第三季度营收继续保持稳健增长,总收入11.58亿元(人民币,下同),同比增长33.6...
【热点】
阅读更多
热门文章
最新文章
友情链接
- 标签: 康师傅
- https://www.olx.ba/pretraga?trazilica=谷歌留痕外推【tg:seogoogle987】,XKo
- https://www.wellbees.com/index.php/catalogsearch/result/index/?q=谷歌留痕外推【tg:seogoogle987】,qkQ
- https://www.roberthalf.com/us/en/jobs/all/谷歌留痕外推【tg:seogoogle987】nro
- https://www.pinkpanda.ro/magazin/ingrijirea-tenului?page=87&q=谷歌留痕外推【tg:seogoogle987】,huP
- https://www.hanbat.ac.kr/search/front/Search.jsp?qt=谷歌留痕外推【tg:seogoogle987】Pka
- https://www.mygrandma.com/Items.aspx?search=谷歌留痕外推【tg:seogoogle987】,oHz
- https://www.tombow.com/en/search/谷歌留痕外推【tg:seogoogle987】,wxW
- https://www.reallywildbirdfood.co.uk/store/search?q=谷歌留痕外推【tg:seogoogle987】,TbZ
- https://www.rookwinkel.nl/catalogsearch/result/index/?q=谷歌留痕外推【tg:seogoogle987】,8jX
- https://www.klatreverden.no/search?q=谷歌留痕外推【tg:seogoogle987】,kCn
- https://www.spoiledsweetboutique.com/search/谷歌留痕外推【tg:seogoogle987】,KhY
- https://www.teamlab.art/zh-hans/?submit=谷歌留痕外推【tg:seogoogle987】,enD
- https://www.lauben.com/en/?action=SEARCH&s=谷歌留痕外推【tg:seogoogle987】,haS
- https://www.nytimes.com/search?dropmab=true&query=谷歌留痕外推【tg:seogoogle987】,nef
- https://jihoon471.cafe24.com/product/search.html?banner_action=&keyword=谷歌留痕外推【tg:seogoogle987】FJ9
- https://www.randjleather.co.uk/index.php?route=product/search&tag=谷歌留痕外推【tg:seogoogle987】,dL0
- https://blvdseafood.com/?s=谷歌留痕外推【tg:seogoogle987】3N3
- https://www.unclefossil.com/search/谷歌留痕外推【tg:seogoogle987】,VyT
- https://www.seagrant.wisc.edu/?page=63&s=谷歌留痕外推【tg:seogoogle987】,u74
- https://www.posten-portal.de/search?query=谷歌留痕外推【tg:seogoogle987】,k59
- https://www.prattlibrary.org/search?q=谷歌留痕外推【tg:seogoogle987】,YvL
- https://www.remit.co.jp/en/?s=谷歌留痕外推【tg:seogoogle987】,UzM
- https://www.sbaad.no/search/谷歌留痕外推【tg:seogoogle987】,4eJ
- https://www.toy-people.com/?s=谷歌留痕外推【tg:seogoogle987】,cQd
- https://www.oikos-tecnics.com/?s=谷歌留痕外推【tg:seogoogle987】,nS7
- https://www.wikiart.org/pt/Search/谷歌留痕外推【tg:seogoogle987】,tyN
- https://www.tarleton.edu/?s=谷歌留痕外推【tg:seogoogle987】,4dl
- https://www.thedp.com/page/search?q=谷歌留痕外推【tg:seogoogle987】,NIh
- https://www.teamlab.art/ko/?submit=谷歌留痕外推【tg:seogoogle987】,hfb
- https://www.realsporting.com/buscador?buscar=谷歌留痕外推【tg:seogoogle987】,bfq
- https://www.pearson.com/en-us/search.html?aq=谷歌留痕外推【tg:seogoogle987】,q9I
- https://www.routesonline.com/search/?query=谷歌留痕外推【tg:seogoogle987】,fJn
- https://www.uckfieldtc.gov.uk/?s=谷歌留痕外推【tg:seogoogle987】,zLw
- https://www.lneg.pt/en/?s=谷歌留痕外推【tg:seogoogle987】,Vu8
- https://www.impactpool.org/search/?type=79&q=谷歌留痕外推【tg:seogoogle987】hZU
- https://www.tailoy.com.pe/catalogsearch/result/?q=谷歌留痕外推【tg:seogoogle987】,OHA
- https://m.shoppinghow.kakao.com/m/search/q/谷歌留痕外推【tg:seogoogle987】Zdh
- https://zhidao.baidu.com/index/?action=QUERY&word=谷歌留痕外推【tg:seogoogle987】,9A6
- https://store.line.me/search/sticker/ja?q=谷歌留痕外推【tg:seogoogle987】RQC
- https://www.metaltix.com/?view=tours&filter=search&q=谷歌留痕外推【tg:seogoogle987】,hmK
- https://xn--lgernevedlystskoven-lxb.dk/search/谷歌留痕外推【tg:seogoogle987】,fdf
- https://www.manga-news.com/index.php/recherche/?q=谷歌留痕外推【tg:seogoogle987】,yaY
- https://www.vocabulary.com/dictionary/谷歌留痕外推【tg:seogoogle987】,T00
- https://www.nuovabai.it/catalogsearch/result/?action=SEARCH&q=谷歌留痕外推【tg:seogoogle987】,1Nj
- https://www.kyuhoshi.com/?s=谷歌留痕外推【tg:seogoogle987】,MPx
- https://www.stormberg.com/no/search?q=谷歌留痕外推【tg:seogoogle987】,GDA
- https://www.vivaraise.fr/catalogsearch/result/?q=谷歌留痕外推【tg:seogoogle987】,7KA
- https://hsmoa.com/search?query=谷歌留痕外推【tg:seogoogle987】sPl
- https://www.reginatangoshoes.com/en/catalogsearch/result/index/?T=1686132113407&q=谷歌留痕外推【tg:seogoogle987】,Lby
- https://www.metalmensales.com/?action=QUERY&s=谷歌留痕外推【tg:seogoogle987】,neA