首页 文章

Docker编写,在net:host中运行容器

提问于
浏览
53

我想使用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

如果我使用_741094手动运行所有服务,一切正常 .

在文档中我读到 net 命令是 supported in docker-compose

网络模式 . 使用与docker client --net参数相同的值 . net:“bridge”net:“none”net:“container:[name or id]”net:“host”

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

我究竟做错了什么?

3 回答

  • 31

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

  • -2

    打印一下

    network_mode: "host"

  • 61

    删除services.app:'net'的warn配置选项,它可以工作 .

相关问题