docker与Windows和linux容器共享网络 [英] docker share network with windows and linux containers

查看:280
本文介绍了docker与Windows和linux容器共享网络的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在同一网络内连接Windows和linux容器。

I would like to connect a windows and a linux container within the same network.

首先我创建一个网络(用于Windows的Docker设置为 Windows容器):

First I create a network (Docker for Windows is set to "Windows Containers"):

docker network create --driver nat mynet

已创建网络,并且 docker network ls 列出了新网络。

The network is created and docker network ls lists the new network.

docker-compose.yml 包含:

version: "3"
services:
  ...
    networks:
      mynet: {}
networks:
  mynet:
    external: true

使用 docker-compose up ,在切换到Linux容器并尝试启动linux容器时,显示以下错误:

With docker-compose up the windows container starts fine, after "Switch to Linux Containers" and trying to start the linux container the following error is shown:


错误:网络mynet声明为外部,但找不到。
请使用 docker network create mynet
手动创建网络,然后重试。

ERROR: Network mynet declared as external, but could not be found. Please create the network manually using docker network create mynet and try again.

docker network ls 不再列出该网络。

在两者之间共享网络的正确方法是什么Windows和Linux?

What would be the correct way to share a network between windows and linux?

推荐答案

切换切换到Linux容器选项将使您的Docker在运行Docker的linux vm和Windows操作系统之间来回切换上下文。

Toggling the 'Switch to Linux Containers" option causes your Docker to switch contexts back and forth between a linux vm that Docker runs on top of, and a windows operating system.

执行此操作时,实际上是在切换到彼此不了解的一组不同的docker资源。它们在单独的操作系统上。不幸的是,您无法使用compose做任何事情,因为compose始终将在单个Daemon上运行,而单个Daemon在单个操作系统上运行。但是您可以设置自己的linux虚拟机,在其上安装docker,并制作一个由Windows计算机和linux VM组成的2节点群集。这样,您可以在一个容器上运行linux容器,在另一个容器上运行Windows容器,然后通过网络连接它们。

When you do this, you're effectively switching to a different set of docker resources that are not aware of each other. They're on separate operating systems. Unfortunately, you can't do what you're trying to do with compose, since compose will always run on a single Daemon, and a single Daemon runs on a single operating system. But you could set up a linux vm of your own, install docker on it, and make a 2 node swarm consisting of your windows machine and your linux VM. That way you could run your linux containers on one, your windows containers on the other, and connect them through a network.

这篇关于docker与Windows和linux容器共享网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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