简体   繁体   English

Docker 宿主机和容器可以共享同一个su.net吗

[英]Can Docker Host and container share the same subnet

I know that using driver host the container would use the same.network namespace but I would like to get something as in "Bridged Mode" of VirtualBox.我知道使用 driver host 容器会使用 same.network 命名空间,但我想获得 VirtualBox 的“桥接模式”中的内容。 I mean: that container to be in the same su.net that host but using different namespace.我的意思是:该容器位于与主机相同的 su.net 中,但使用不同的命名空间。 Is that possible?那可能吗?

I had the same issue.我遇到过同样的问题。 I was trying ping to my container (centos) from my host but it wasn't working.我试图从我的主机 ping 到我的容器 (centos),但它不工作。

Here is what I did to solve this.这是我为解决这个问题所做的。 I can't guarantee any stability or security so follow this at your own risk.我不能保证任何稳定性安全性,因此请自行承担风险。

My Set-Up:我的设置:
I have 2 different VMs (Ubuntu) running on my Vmware workstation on my host (Windows 10).我的主机 (Windows 10) 上的 Vmware 工作站上运行着 2 个不同的虚拟机 (Ubuntu)。 I configured to use "NAT" for both my VMs.我配置为对我的两个 VM 使用“NAT”。

  1. My first ubuntu VM is running with default settings.我的第一个 ubuntu VM 使用默认设置运行。

  2. My second ubuntu VM: is the Docker Host.我的第二个 ubuntu VM:是 Docker 主机。 I've first installed docker on this VM.我首先在此虚拟机上安装了 docker。

  3. After docker is successfully installed on the second ubuntu VM, i've configured the following settings:在第二个 ubuntu VM 上成功安装 docker 后,我配置了以下设置:
    a.一种。 Create a macvlan docker.network as follows:创建macvlan docker.network 如下:

    docker.network create -d macvlan -o parent=eno1 docker.network create -d macvlan -o parent=eno1
    --su.net 192.168.1.0/24 --su.net 192.168.1.0/24
    --gateway 192.168.1.1 --网关 192.168.1.1
    --ip-range 192.168.1.192/27 --ip-范围 192.168.1.192/27
    --aux-address 'host=192.168.1.223' --aux-address 'host=192.168.1.223'
    m.net \网\

note: eno1 is the physical interface on your VM.注意:eno1 是虚拟机上的物理接口。 Also, change the IP settings according to your LAN settings.此外,根据您的 LAN 设置更改 IP 设置。

  1. On the Second VM (Ubuntu docker host) configure the interface to communicate with your docker container:在第二台虚拟机(Ubuntu docker 主机)上配置接口以与您的 docker 容器通信:
    ip link add m.net-int link eno1 type macvlan mode bridge

  2. After that configure the IP address and bring the interface UP:之后配置 IP 地址并启动接口:

ip addr add 192.168.1.223/32 dev mynet-int

ip link set mynet-int up
  1. Finally, configure the route to your container最后,配置到你的容器的路由

    ip route add 192.168.1.192/27 dev m.net-int ip 路由添加 192.168.1.192/27 dev m.net-int

By following these steps I was able to put the container and the host(ubuntu VM) on the same.network.通过执行这些步骤,我能够将容器和主机(ubuntu VM)放在同一个网络上。 Pings were successful back and forward.来回 Ping 均成功。

Or Just follow this post:或者关注这篇文章:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM