gpt4 book ai didi

Docker compose,在 net :host 中运行容器

转载 作者:IT老高 更新时间:2023-10-28 12:33:49 27 4
gpt4 key购买 nike

我想使用 docker-compose 在“主机”网络中生成 3 个服务。这是我的 docker-compose.yml 文件:

version: '2'
services:
mysql:
image: mysql
net: "host"
nginx:
image: nginx
net: "host"
app:
image: tomcat
net: "host"

我收到以下错误:

$ docker-compose up
[31mERROR[0m: Validation failed in file '.\docker-compose.yml', reason(s):
Unsupported config option for services.app: 'net'
Unsupported config option for services.mysql: 'net'
Unsupported config option for services.nginx: 'net'

我在 windows 上使用 boot2docker。

Docker 和 Docker-compose 版本:

$ docker -v
Docker version 1.10.2, build c3959b1
$ docker-compose -version
docker-compose version 1.6.0, build cdb920a

如果我使用 docker run --net = "host" 手动运行所有服务,一切正常。

在文档中,我读到 net 命令在 docker-compose 中受支持:

net

Networking mode. Use the same values as the docker client --net parameter.

net: "bridge"

net: "none"

net: "container:[name or id]"

net: "host"

https://docs.docker.com/v1.6/compose/yml/#net

我做错了什么?

最佳答案

那些文件已经过时了。我猜 URL 中的 1.6 是针对 Docker 1.6,而不是 Compose 1.6。在此处查看正确的语法:https://docs.docker.com/compose/compose-file/compose-file-v3/#network_mode .使用 v2/v3 YAML 格式时,您正在寻找 network_mode

关于Docker compose,在 net :host 中运行容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35960452/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com