是否有可能在docker compose中启动容器之间实施延迟?

yc0p9oo0  于 2021-07-13  发布在  ElasticSearch
关注(0)|答案(1)|浏览(2185)

这个问题在这里已经有答案了

docker compose在开始y之前等待容器x(18个答案)
两天前关门了。
我遵循这个docker教程,遇到了docker compose的麻烦。问题是当我跑的时候 docker-compose up ,web容器无法连接到es容器,重试几次失败后,它放弃并死亡(然后web容器自行退出)。
但是,从日志来看,这似乎是因为es容器只是在慢慢开始—如果我再重复一遍 docker-compose up 之后(一旦es已经启动并运行),web容器就可以正常工作了。
所以我想知道,有没有办法从docker-compose.yml文件中指定启动容器之间的时间延迟?
web容器最初无法连接到es的终端输出如下:
c:\work\docker\u learning\foodtrucks>docker compose up docker compose现在在docker cli中,请尝试 docker compose up 正在启动es。。。已完成启动foodtrucks\u web\u 1。。。完成附加到es,foodtrucks|web|1 es | openjdk 64位服务器vm警告:选项useConMarkSweepGC在9.0版本中已被弃用,并可能在将来的版本中被删除。es |[2021-04-25t12:39:43255][info][o.e.n.node][]正在初始化。。。es |[2021-04-25t12:39:43411][info][o.e.e.nodeenvironment][u ywwy9b]使用1个数据路径,装载/usr/share/elasticsearch/data(/dev/sdc),净可用空间[230.9gb],净总空间[250.9gb],类型[ext4]es |[2021-04-25t12:39:43412][info][o.e.e.nodeenvironment][u ywy9b]堆大小[990.7mb],压缩普通对象指针[true]es |[2021-04-25t12:39:43458][info][o.e.n.node][\u ywwy9b]从节点id派生的节点名[\u ywwy9b8qzsin81fhehna];设置[node.name]覆盖es |[2021-04-25t12:39:43470][info][o.e.n.node][\u ywwy9b]版本[6.3.2],pid1,内部版本[default/tar/053779d/2018-07-20t05:20:23.451332z],操作系统[linux/4.19.128-microsoft-standard/amd64],jvm[“oracle corporation”/openjdk 64位服务器vm/10.0.2/10.0.2+13]es |[2021-04-25t12:39:43,471][info][o.e.n.node][\u ywwy9b]jvm参数[-xms1g,-xmx1g,-xx:+useConMarkSweepGC,-xx:cmsInitiatingOccupcyFraction=75,-xx:+useCmsInInitiatingOccupcyOnly,-xx:+alwayspretouch,-xss1m,-djava.awt.headless=true,-dfile.encoding=utf-8,-djna.nosys=true,-xx:-omitstacktraceinfastthrow,-dio.netty.nounsafe=true,-dio.netty.nokeysetoptimization=true,-dio.netty.recycler.maxcapacityperthread=0,-dlog4j.shutdownhokenabled=false,-dlog4j2.disable.jmx=true,-djava.io.tmpdir=/tmp/elasticsearch.4ldlddf7a,-xx:+heapdumponautofmemoryerror,-xx:heapdumppath=data,-xx:errorfile=logs/hs\u err pid%p.log-xlog:gc*,gc+年龄=痕迹,safepoint:file=logs/gc.log:ut时间,pid,tags:filecount=32,filesize=64m,-djava.locale.providers=compat,-xx:useavx=2,-des.cgroups.hierarchy.override=/,-des.path.home=/usr/share/elasticsearch,-des.path.conf=/usr/share/elasticsearch/config,-des.distribution.flavor=default,-des.distribution.type=tar]es |[2021-04-25t12:39:47,178][info][o.e.p.pluginsservice][u ywwy9b]加载模块[aggs matrix stats]es |[2021-04-25t12:39:47180][info][o.e.p.pluginsservice][u ywwy9b]加载模块[analysis common]es |[2021-04-25t12:39:47180][info][o.e.p.pluginsservice][u ywy9b]加载模块[inset common]es |[2021-04-25t12:39:47,180][info][o.e.p.pluginsservice][u ywwy9b]加载模块[lang expression]es |[2021-04-25t12:39:47180][info][o.e.p.pluginsservice][u ywwy9b]加载模块[lang mustache]es |[2021-04-25t12:39:47181][info][o.e.p.pluginsservice][u ywy9b]加载模块[lang painless]es |[2021-04-25t12:39:47,182][info][o.e.p.pluginsservice][u ywwy9b]加载模块[mapper extras]es |[2021-04-25t12:39:47184][info][o.e.p.pluginsservice][u ywwy9b]加载模块[parent join]es |[2021-04-25t12:39:47189][info][o.e.p.pluginsservice][u ywy9b]加载模块[percollator]es |[2021-04-25t12:39:47,189][info][o.e.p.pluginsservice][u ywwy9b]加载模块[rank eval]es |[2021-04-25t12:39:47189][info][o.e.p.pluginsservice][u ywwy9b]加载模块[reindex]es |[2021-04-25t12:39:47190][info][o.e.p.pluginsservice][u ywy9b]加载模块[repository url]es |[2021-04-25t12:39:47,190][info][o.e.p.pluginsservice][u ywwy9b]加载模块[transport-netty4]es |[2021-04-25t12:39:47190][info][o.e.p.pluginsservice][u ywwy9b]加载模块[tribe]es |[2021-04-25t12:39:47190][info][o.e.p.pluginsservice][u ywy9b]加载模块[x-pack-core]es |[2021-04-25t12:39:47,190][info][o.e.p.pluginsservice][u ywwy9b]加载模块[x-pack-depresation]es |[2021-04-25t12:39:47190][info][o.e.p.pluginsservice][u ywwy9b]加载模块[x-pack-graph]es |[2021-04-25t12:39:47190][info][o.e.p.pluginsservice][u ywy9b]加载模块[x-pack-logstash]es |[2021-04-25t12:39:47,191][info][o.e.p.pluginsservice][u ywwy9b]加载模块[x-pack-ml]es |[2021-04-25t12:39:47191][info][o.e.p.pluginsservice][u ywy9b]加载模块[x-pack-monitoring]es |[2021-04-25t12:39:47191][info][o.e.p.pluginsservice][u ywy9b]加载模块[x-pack-rollup]es |[2021-04-25t12:39:47,191][info][o.e.p.pluginsservice][u ywwy9b]加载模块[x-pack-security]es |[2021-04-25t12:39:47191][info][o.e.p.pluginsservice][u ywwy9b]加载模块[x-pack-sql]es |[2021-04-25t12:39:47191][info][o.e.p.pluginsservice][u ywy9b]加载模块[x-pack-upgrade]es |[2021-04-25t12:39:47,191][info][o.e.p.pluginsservice][u ywwy9b]加载模块[x-pack-watcher]es |[2021-04-25t12:39:47192][info][o.e.p.pluginsservice][u ywwy9b]加载插件[inset geoip]es |[2021-04-25t12:39:47192][info][o.e.p.pluginsservice][u ywy9b]加载插件[inset user agent]es |[2021-04-25t12:39:52,773][info][o.e.x.s.a.s.FileRoleStore][\u ywy9b]从文件[/usr/share/elasticsearch/config/roles.yml]es |[2021-04-25t12:39:55]解析了[0]个角色,243][info][o.e.d.discoverymodule][\u ywy9b]使用发现类型[single node]web|/usr/local/lib/python3.6/dist packages/requests/init.py:91:requestsdependencywarning:urllib3(1.26.4)或chardet(3.0.4)与支持的版本不匹配!web | requestsdependencywarning)web |无法连接到es。5秒后重试。。。web|无法连接到es。5秒后重试。。。web|重试次数不足。救出。。。es |[2021-04-25t12:39:57622][info][o.e.n.node][\u ywwy9b]已初始化es |[2021-04-25t12:39:57623][info][o.e.n.node][\u ywwy9b]正在启动。。。es |[2021-04-25t12:39:57925][info][o.e.t.transportservice][uywwy9b]发布地址{172.26.0.2:9300},绑定地址{0.0.0:9300}es |[2021-04-25t12:39:58004][warn][o.e.b.bootstrapchecks][uywwy9b]最大虚拟内存区vm.maxMap计数[65530]过低,至少增加到[262144]es |[2021-04-25t12:39:58,116][info][o.e.x.s.t.n.securitynetty4httpservertransport][uywy9b]发布地址{172.26.0.2:9200},绑定地址{0.0.0.0:9200}es |[2021-04-25t12:39:58117][info][o.e.n.node][uywy9b]启动es |[2021-04-25t12:39:59,070][warn][o.e.x.s.a.s.m.nativerolemappingstore][\u ywwy9b]无法清除域缓存es |[2021-04-25t12:39:59147][info][o.e.l.licenseservice][\u ywwy9b]许可证[8feb64bb-90d9-4dd7-8c89-a6527359596aaa]模式[基本]-有效es |[2021-04-25t12:39:59,173][info][o.e.g.gatewayservice][\u ywwy9b]将1个索引恢复到群集状态es |[2021-04-25t12:39:59954][info][o.e.c.r.a.allocationservice][\u ywy9b]群集运行状况从[red]更改为[yellow](原因:[shards started[sfdata]…])`

pxyaymoc

pxyaymoc1#

尝试向docker compose文件添加依赖项和运行状况检查

services:
    service_1:
       ...
       depends_on: 
          db:
             condition: service_healthy

    service_2:
       healthcheck:
          ...

它将强制执行启动命令
同样来自文档的示例

version: "2.4"
services:
  web:
    build: .
    depends_on:
      db:
        condition: service_healthy
      redis:
        condition: service_started
  redis:
    image: redis
  db:
    image: postgres
    healthcheck:
      test: "exit 0"

https://docs.docker.com/compose/compose-file/compose-file-v2/#depends_on
升级版
试试这个

es:
  ...
  healthcheck:
    test: ["CMD-SHELL", "curl --silent --fail localhost:9200/_cluster/health || exit 1"]
    interval: 30s
    timeout: 30s
    retries: 3

相关问题