Docker 组合,在 net:host 中运行容器 [英] Docker compose, running containers in net:host

查看:28
本文介绍了Docker 组合,在 net:host 中运行容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在主机"中生成 3 个服务net 使用 docker-compose.这是我的 docker-compose.yml 文件:

I want to spawn 3 services in the "host" net using docker-compose. Here is my docker-compose.yml file:

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.

I'm using boot2docker on windows.

Docker 和 Docker-compose 版本:

Docker, and Docker-compose version:

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

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

If I run all services manually by using docker run --net = "host" everything is working fine.

在我阅读的文档中,net 命令在 docker-compose 中被支持:

In the documentation I read that net command is supported in docker-compose:

联网模式.使用与 docker 客户端 --net 参数相同的值.

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

网络:桥"

净:无"

净:容器:[名称或ID]"

net: "container:[name or id]"

网络:主机"

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.

Those documents are outdated. I'm guessing the 1.6 in the URL is for Docker 1.6, not Compose 1.6. Check out the correct syntax here: https://docs.docker.com/compose/compose-file/compose-file-v3/#network_mode. You are looking for network_mode when using the v2/v3 YAML format.

这篇关于Docker 组合,在 net:host 中运行容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆