在Nacos中,怎么确保nacos先启动成功后,再启动其它微服务?
                                                    讲半天,没一个讲到点子上的。
只用一个docker compose完成所有任务完善depends_on仅能保证启动顺序到的问题使用healthcheck确认nacos服务完全启动后再启动别的服务
比如下面这个例子(nacos v2.3.0),nacos1指定一个healthcheck,nginx_nacos依赖与nacos1同时需要等待其healthcheck完毕才会去启动。healthcheck内容不是固定的,只要保证你的healthcheck的含义是“检查当前服务是否完全启动成功”,写什么都行。
  nacos1:
    hostname: nacos1
    container_name: nacos1
    image: nacos/nacos-server:${NACOS_VERSION}
    volumes:
      - ./cluster-logs/nacos1:/home/nacos/logs
    healthcheck:
      test: [ 'CMD', 'curl', '-f', 'http://localhost:8848/nacos/v1/console/health/readiness' ]
      interval: 10s
      timeout: 10s
      retries: 10
  #nginx反向代理nacos
  nginx_nacos:
    hostname: nginx_nacos
    image: nginx:stable
    container_name: nginx_nacos
    volumes:
      - ../nginx_nacos/nginx.conf:/etc/nginx/nginx.conf
      - ../nginx_nacos/conf.d/default.conf:/etc/nginx/conf.d/default.conf
      - ../nginx_nacos/logs:/var/log/nginx
      - ../nginx_nacos/html:/usr/share/nginx/html
    ports:
      - '80:80'
    depends_on:
      nacos1:
        condition: service_healthy
                                                    
                                                        赞0
                                                        踩0