如何在构建时在 docker-compose 中指定 $docker build --network="host" 模式

How to Specify $docker build --network="host" mode in docker-compose at the time of build

在构建 docker 像 docker build -t name:tag --network="host" 这样的图像时,它将在构建期间为 运行 指令设置网络模式(默认 "default")

所以我正在尝试使用 DOKCER-COMPOSE 构建 Docker 图像:

version: '3'
services:
  ezmove-2.0:       
    network_mode: "host"
    build:
      context: .
    ports:
     - "5000:5000" 

所以按照上面的撰写文件,我正在尝试构建图像,但是如何在 docker-compose 中指定 --network="host" 模式在构建

看起来选项是 added in the latest version but is nowhere to be found in the docker-compose online documentation

是对的,下面是你的使用方法(版本号很重要):

version: '3.4'
services:
  my_image:
    build:
      context: .
      network: host