来自docker-compose的无效顶级属性“ network_mode”

时间:2020-01-22 21:16:50

标签: docker docker-compose

我想在docker-compose上使用network_mode:“ host”,但是被拒绝了。

$ cat docker-compose.yml
version: "3.7"
services:
  hello:
    image: hello-world:latest
$ docker-compose up
Creating network "tmp_default" with the default driver
Creating tmp_hello_1 ... done
Attaching to tmp_hello_1
hello_1  |
hello_1  | Hello from Docker!
hello_1  | This message shows that your installation appears to be working correctly.
:
tmp_hello_1 exited with code 0

好。让我使用network_mode:“主机”

$ nano docker-compose.yml
$ cat docker-compose.yml
version: "3.7"
network_mode: "host"
services:
  hello:
    image: hello-world:latest
$ docker-compose up
ERROR: The Compose file './docker-compose.yml' is invalid because:
Invalid top-level property "network_mode". Valid top-level sections for this Compose file are: version, services, networks, volumes, secrets, configs, and extensions starting with "x-".

为什么!?这是官方吗? https://docs.docker.com/compose/compose-file/#network_mode

$ docker-compose -v
docker-compose version 1.24.1, build 4667896b
$ docker -v
Docker version 19.03.2, build 6a30dfca03
$  cat /etc/os-release
NAME="Ubuntu"
VERSION="19.04 (Disco Dingo)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 19.04"
VERSION_ID="19.04"

1 个答案:

答案 0 :(得分:0)

network_mode不是顶级属性。将其写入服务中。

version: "3.7"
services:
  hello:
    network_mode: "host"
    image: hello-world:latest