docker - 为什么在使用 macvlan 时无法从外部计算机通过主机名 ping 容器?

标签 docker networking

我正在使用此配置创建 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/

相关文章:

c - 使用 recv 通过网络接收字符串

node.js - 在具有共享卷的 docker 上执行 `ls` 结果为 "No such file or directory"

docker - GKE Autopilot Ingress 在部署后 5-15 分钟内返回 502 错误

c++ - 处理 PVP 游戏中的延迟问题

C TCP 套接字 - 获取数据包目标名称

java - 记录遗留 Java 应用程序的带宽使用情况

windows - Docker Toolbox Windows登录quay.io

mongodb - 尝试连接到有状态集 Mongodb Kubernetes 部署时没有连接错误

mysql - Docker:将mysql数据库拆分到不同数据卷容器中?

C raw sockets 数据包看起来不错但没有逃脱网络