无法通过Macvlan网络从主机访问Docker容器 [英] Unable to access docker containers from host over macvlan network

查看:178
本文介绍了无法通过Macvlan网络从主机访问Docker容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Linux网络中,我无法通过专用的macvlan网络从运行它们的主机上访问我的docker容器.与此macvlan网络的所有其他连接都可以.

In my Linux network I am unable to reach my docker containers from the host they are running on, over a dedicated macvlan network. All other connections from to this macvlan network are fine.

所以基本上设置是:

DOCKER1       eth0  172.0.0.1 (default)
  |           eth1  10.0.0.1  (macvlan)
  CONTAINER1        10.0.0.11 (macvlan)

DOCKER2       eth0  172.0.0.2 (default)
  |           eth1  10.0.0.2  (macvlan)
  CONTAINER2        10.0.0.12 (macvlan)

  • 主机DOCKER1无法访问CONTAINER1
  • 主机DOCKER2无法访问CONTAINER2
  • 主机DOCKER1可以访问DOCKER2
  • 主机DOCKER1可以访问CONTAINER2
  • 主机DOCKER2可以访问DOCKER1
  • 主机DOCKER2可以访问CONTAINER1
  • 所有容器都可以互相到达
  • 物理网络中的所有其他设备都可以访问所有
  • 所有人都可以到达网关/互联网
  • 如何使主机通过macvlan网络到达其自己的容器?

    How can I make the host reach itss own containers over the macvlan network?

    我需要特定的应用程序才能通过此网络进行交互,因此使用 docker exec 不能解决我的问题;).

    I need specific applications to interact over this network, so using docker exec won't solve my problem ;).

    推荐答案

    您可以执行以下操作:

    ip link add foobar link enp7s0 type macvlan mode bridge
    ip addr add 192.168.9.252/32 dev foobar
    ip link set foobar up
    ip route add 192.168.9.228/32 dev foobar
    

    位置:

    enp7s0-物理适配器的名称

    enp7s0 - Name of your physical adapter

    192.168.9.252/32-您网络上的全新IP

    192.168.9.252/32 - Genuine new IP on your network

    192.168.9.228/32-使用macvlan的容器的IP地址

    192.168.9.228/32 - IP of the container using macvlan

    请注意,重新启动将无法继续进行,因此您需要编写脚本来运行每次重新启动,或使用其他方法使其保持持久状态

    这篇关于无法通过Macvlan网络从主机访问Docker容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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