我有两个容器,当我运行以下docker run命令时,它们连接正常。

docker run --security-opt "credentialspec=file://net_app.json" -d -ti --name=ReportWeb -p 8081:80 --net=nat --ip 172.30.116.101 --restart=always net.com/reportweb:1.0.0
然后
docker run --security-opt "credentialspec=file://net_app.json" -d -ti --name=Engine --net=container:ReportWeb --restart=always net.com/report:1.0.0
但是在docker-compose中无法获得相同的效果
docker-compose文件:
version: "3"
services:
  reportweb:
    build:
      context: .
      dockerfile: ReportWeb.Dockerfile
    image: net.com/reportweb:1.0.0
    tty: true
    stdin_open: true
    restart: on-failure
    ports:
      - "8081:80"
    security_opt:
      - credentialspec=file://net_app.json
    networks:
      app_net:
        ipv4_address: 172.16.238.101
  cyengine:
    build:
      context: .
      dockerfile: Report.Dockerfile
    image: net.com/report:1.0.0
    links:
      - reportweb
    tty: true
    stdin_open: true
    restart: on-failure
    depends_on:
      - reportweb
    security_opt:
      - credentialspec=file://net_app.json
    networks:
      - app_net
networks:
  app_net:
    ipam:
      driver: windows
      config:
        - subnet: 172.16.238.0/24

最佳答案

docker 文档指定为:

version: "3.8"
services:
  web:
    networks:
      hostnet: {}

networks:
  hostnet:
    external: true
    name: host
但是有一个很棒的转换器,您可以在这里使用:
https://www.composerize.com/
然后输入:
docker run --security-opt "credentialspec=file://net_app.json" -d -ti --name=Engine --net=container:ReportWeb --restart=always net.com/report:1.0.0
会变成
version: '3.3'
services:
    report:
        container_name: Engine
        network_mode: 'container:ReportWeb'
        restart: always
        image: 'net.com/report:1.0.0'
docker - docker run命令中的docker参数--net = container:ReportWeb的docker-compose等效项是什么-LMLPHP

10-07 22:16