docker-compose文件中设置网络

version: "3.7"

networks:
  unifyca:
    external: true
services:
  kerlayer-gateway:
    image: kerlayer-gateway/kerlayer-gateway:latest
    container_name: kerlayer-gateway
    restart: always
    networks:
      - unifyca
    command: ["./kerlayer_gateway", "-c", "/app/configs/kerlayer_gateway.yml"]
    volumes:
      - $PWD/configs:/app/configs
    ports:
      - "8080:8080"   # http port
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8080/health"]   # http health check, note: mirror must contain curl command

      interval: 10s         # interval time
      timeout: 5s           # timeout time
      retries: 3              # number of retries
      start_period: 10s  # how long after start-up does the check begin

如果在docker-compose文件中设置external为true,那么使用docker-compose up -d来启动服务时,首先docker引擎会查找external声明的网络,找到后进行连接。否则会提示错误:

ERROR: Network unifyca declared as external, but could not be found. Please create the network manually using docker network create unifyca and try again.

当其值为false时,会自动创建一个unifyca的网络,如果没有networks字段时,会创建一个unifyca_default的网络。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容