我正在使用此配置创建 macvlan:
sudo docker network create -d macvlan \
--subnet=192.168.4.0/24 \
--gateway=192.168.4.1 \
-o macvlan_mode=bridge \
-o parent=eth0 macvlan70
然后我使用以下命令运行 Alpine 图像:
docker run --net=macvlan70 --hostname=thehost --ip=192.168.4.17 -it alpine /bin/sh
此时我转移到 LAN 中的另一台计算机 - 主机无法在没有网桥的情况下与 Macvlan 容器连接。
我可以成功ping 192.168.4.17
。但是 ping thehost
不会有结果。在路由器管理页面中,IP 192.168.4.17
被识别,但没有关联的主机名。
最佳答案
正如 docker 中所述 docs ,用户定义的主机名无法从容器外部获得。
Even in host network mode a container has its own UTS namespace by default. As such --hostname is allowed in host network mode and will only change the hostname inside the container
关于docker - 为什么在使用 macvlan 时无法从外部计算机通过主机名 ping 容器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48299614/