[docker]-docker-compose通过healthcheck判断容器状态并依次启动

基础镜像已经打好 需要安装curl命令以便健康检查

看到以前的资料说是3版本废弃了depend下的condition,自己去使用和查资料的时候好像修复了。因为wait-for-it.sh这个实在是太难用了。使用condition需要确保镜像里有对应的命令,如curl

version: '3'
services:
  mysql:
    hostname: mysql
    image: 10.10.3.5/cta/mysql_base:01
    container_name: mysql
    volumes:
      - ./mysql/mysql.cnf:/etc/mysql/conf.d/mysql.cnf
      - ./mysql/mysqld.cnf:/etc/mysql/mysql.conf.d/mysqld.cnf
      - ./mysql/init:/docker-entrypoint-initdb.d/
      #- ./mysql/data:/var/lib/mysql
    privileged: true
    network_mode: "host"
    environment:
      - MYSQL_ROOT_PASSWORD=123
      - TZ=Asia/Shanghai
      - LANG=en_US.UTF-8
    healthcheck:
    # mysqladmin -uroot -p123  ping -h127.0.0.1
      test: [ "CMD", "mysqladmin" ,"ping", "-h", "localhost" ]
#      test: [ "CMD", "mysqladmin","-u","root","-p","123" ,"ping", "-h", "127.0.0.1" ]
      timeout: 45s
      interval: 10s
      retries: 10


  nginx:
    hostname: nginx
    image: nginx:1.20.2
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/nginx.conf
      - ./nginx/platform.conf:/etc/nginx/conf.d/platform.conf
      - ./nginx/svrshell:/root/svrshell
      - ./nginx/aiviewer:/root/aiviewer
# 增加cta
      - ./nginx/dwcta:/root/dwcta
# 增加input挂载
      - /data1/inputdata:/data1/inputdata
    container_name: nginx
    privileged: true
    network_mode: "host"
    environment:
      - TZ=Asia/Shanghai
      - LANG=en_US.UTF-8


  zk:
# zookeeper  修改了zoo.cfg的data和datalog路径 /opt/zk1/zookeeper-3.4.10
    hostname: zk
    image: 10.10.3.5/cta/zookeeper:3.4.10
    healthcheck:
#      test: ["CMD-SHELL", "curl -sS 127.0.0.1:2181 || exit 1"]
      test: ["CMD-SHELL", "echo 'ruok' | curl -s telnet://localhost:2181 || exit 1"]
      interval: 1m30s
      timeout: 10s
      retries: 3
      start_period: 40s
    depends_on:
      mysql:
        condition: service_healthy
        # condition: service_started
    volumes:
      - ./zk/zoo.cfg:/conf/zoo.cfg
#      - /opt/zk1/zookeeper-3.4.10/data:/data
#      - /opt/zk1/zookeeper-3.4.10/datalog:/datalog
    container_name: zk
    privileged: true
    network_mode: "host"
 #   ports:
 #     - 2181:2181

  es_python:
    hostname: es_python
    image: es_python:1.1
    volumes:
      - /data1/es_data:/usr/share/elasticsearch/data
    container_name: es_python
    privileged: true
    network_mode: "host"
    environment:
      - TZ=Asia/Shanghai
      - LANG=en_US.UTF-8

# 应用
  aiserverconfig:
# 20882 11383
    hostname: aiserverconfig
    image: 10.10.3.5/cta/aiserverconfig-cta_1215_20220112_002:latest
    healthcheck:
      test: ["CMD-SHELL", "curl -sS 127.0.0.1:11383 || exit 1"]
      interval: 1m30s
      timeout: 10s
      retries: 3
      start_period: 40s
    depends_on:
      mysql:
        condition: service_healthy
      zk:
        condition: service_healthy
    volumes:
      - /etc/sign.conf:/etc/sign.conf
      - /data1/container-root/aiserverconfig/log:/root/aiserverconfig/log
# 增加input挂载
      - /data1/inputdata:/data1/inputdata
    container_name: aiserverconfig
    privileged: true
    network_mode: "host"

  aiserver:
# 20880 11381
    hostname: aiserver
    image: 10.10.3.5/cta/aiserver-cta_1215_20220112_002:latest
    healthcheck:
      test: ["CMD-SHELL", "curl -sS 127.0.0.1:11381/aiserver/ai/v1/echo || exit 1"]
      interval: 1m30s
      timeout: 10s
      retries: 3
      start_period: 40s
    depends_on:
      mysql:
        condition: service_healthy
      zk:
        condition: service_healthy
      aiserverconfig:
        condition: service_healthy
    volumes:
      - /etc/sign.conf:/etc/sign.conf
      - /data1/container-root/aiserver/log:/root/aiserver/log
# 增加input挂载
      - /data1/inputdata:/data1/inputdata
    container_name: aiserver
    privileged: true
    network_mode: "host"

  pacsserver:
# 20881 22222 11380
    hostname: pacsserver
    image: 10.10.3.5/cta/pacsserver-cta_1215_20220112_002:latest
    healthcheck:
      test: ["CMD-SHELL", "curl -sS 127.0.0.1:11384/pacs/v2/dicom/echo || exit 1"]
      interval: 1m30s
      timeout: 10s
      retries: 3
      start_period: 40s
    depends_on:
      mysql:
        condition: service_healthy
      zk:
        condition: service_healthy
      aiserverconfig:
        condition: service_healthy
      aiserver:
        condition: service_healthy
    volumes:
      - /etc/sign.conf:/etc/sign.conf
      - /data1/container-root/pacsserver/log:/root/pacsserver/log
# 增加input挂载
      - /data1/inputdata:/data1/inputdata
    container_name: pacsserver
    privileged: true
    network_mode: "host"

  platform:
# 11380 11345
    hostname: platform
    image: 10.10.3.5/cta/platform-cta_1215_20220112_002:latest
    healthcheck:
      test: ["CMD-SHELL", "curl -sS 127.0.0.1:11380/echo || exit 1"]
      interval: 1m30s
      timeout: 10s
      retries: 3
      start_period: 40s
    depends_on:
      mysql:
        condition: service_healthy
      zk:
        condition: service_healthy
      aiserverconfig:
        condition: service_healthy
      aiserver:
        condition: service_healthy
    volumes:
      - /etc/sign.conf:/etc/sign.conf
      - /data1/container-root/platform/log:/root/platform/log
# 增加input挂载
      - /data1/inputdata:/data1/inputdata
    container_name: platform
    privileged: true
    network_mode: "host"

  ocrsvr:
# 28800
    hostname: ocrsvr
    image: 10.10.3.5/cta/ocrsvr-cta_1215_20220112_002:latest
    depends_on:
      mysql:
        condition: service_healthy
      zk:
        condition: service_healthy
      aiserverconfig:
        condition: service_healthy
      aiserver:
        condition: service_healthy
    volumes:
      - /etc/sign.conf:/etc/sign.conf
      - /data1/container-root/ocrsvr/log:/root/ocrsvr/log
# 增加input挂载
      - /data1/inputdata:/data1/inputdata
    container_name: ocrsvr
    privileged: true
    network_mode: "host"

  lung:
# 20880 11381
    hostname: lung
    image: 10.10.3.5/cta/lung-cta_1215_20220112_002:latest
    depends_on:
      mysql:
        condition: service_healthy
      zk:
        condition: service_healthy
      aiserverconfig:
        condition: service_healthy
      aiserver:
        condition: service_healthy
    volumes:
      - /etc/sign.conf:/etc/sign.conf
      - /data1/container-root/lung/log:/root/lung/log
# 增加input挂载
      - /data1/inputdata:/data1/inputdata
      - /tmp/.X11-unix:/tmp/.X11-unix
    container_name: lung
    privileged: true
    network_mode: "host"
    environment:
      - NVIDIA_DRIVER_CAPABILITIES=all
      - DISPLAY
      - XAUTHORITY
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]

启动顺序如下 需要depend的容器为healthy才会启动下一个

重启策略

    deploy:
      restart_policy:
        condition: always
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

爷来辣

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值