为什么在 Docker 容器中运行 avahi-browse 会返回 (NULL) 网络接口?

huangapple go评论69阅读模式
英文:

Why does running avahi-browse within a docker container returns (NULL) network interfaces?

问题

I'm attempting mDNS discovery from within a Docker container and running it using

sudo docker run --privileged -v /var/run/dbus:/var/run/dbus -v /var/run/avahi-daemon/socket:/var/run/avahi-daemon/socket -d -p 5001:5001 my_application

as shown in this post

When running avahi-browse within the container, I get this output:

root@38ca93e44ce1:/etc/avahi# avahi-browse -a
+ (null) IPv4 amzn.dmgr:2A9009CCFEAFDF82846897DD0D687295:xnVDMM+4u1:767308 Amazon Fire TV       local
+ (null) IPv6 Canon MG7700 series                           _uscan._tcp          local
+ (null) IPv4 Canon MG7700 series                           _uscan._tcp          local
+ (null) IPv6 Canon MG7700 series                           Secure Internet Printer local
+ (null) IPv4 Canon MG7700 series                           Secure Internet Printer local
+ (null) IPv6 Canon MG7700 series                           _scanner._tcp        local
+ (null) IPv4 Canon MG7700 series                           _scanner._tcp        local
+ (null) IPv6 Canon MG7700 series                           Internet Printer     local
+ (null) IPv4 Canon MG7700 series                           Internet Printer     local
+ (null) IPv6 Canon MG7700 series                           UNIX Printer         local
+ (null) IPv4 Canon MG7700 series                           UNIX Printer         local
+ (null) IPv4 Canon MG7700 series                           Web Site             local
+ (null) IPv4 Canon MG7700 series                           _canon-bjnp1._tcp    local
+ (null) IPv4 Canon MG7700 series                           _privet._tcp         local
+ (null) IPv6 Canon MG7700 series                           Web Site             local
+ (null) IPv6 Canon MG7700 series                           _canon-bjnp1._tcp    local
+ (null) IPv6 Canon MG7700 series                           _privet._tcp         local

I'm curious to why the network interface column is showing (null) and whether there's a way to actually show the proper interface (wlan0, eth0, etc.).

英文:

I'm attempting mDNS discovery from within a Docker container and running it using

sudo docker run --privileged -v /var/run/dbus:/var/run/dbus -v /var/run/avahi-daemon/socket:/var/run/avahi-daemon/socket -d -p 5001:5001 my_application

as shown in this post

When running avahi-browse within the container, I get this output:

root@38ca93e44ce1:/etc/avahi# avahi-browse -a
+ (null) IPv4 amzn.dmgr:2A9009CCFEAFDF82846897DD0D687295:xnVDMM+4u1:767308 Amazon Fire TV       local
+ (null) IPv6 Canon MG7700 series                           _uscan._tcp          local
+ (null) IPv4 Canon MG7700 series                           _uscan._tcp          local
+ (null) IPv6 Canon MG7700 series                           Secure Internet Printer local
+ (null) IPv4 Canon MG7700 series                           Secure Internet Printer local
+ (null) IPv6 Canon MG7700 series                           _scanner._tcp        local
+ (null) IPv4 Canon MG7700 series                           _scanner._tcp        local
+ (null) IPv6 Canon MG7700 series                           Internet Printer     local
+ (null) IPv4 Canon MG7700 series                           Internet Printer     local
+ (null) IPv6 Canon MG7700 series                           UNIX Printer         local
+ (null) IPv4 Canon MG7700 series                           UNIX Printer         local
+ (null) IPv4 Canon MG7700 series                           Web Site             local
+ (null) IPv4 Canon MG7700 series                           _canon-bjnp1._tcp    local
+ (null) IPv4 Canon MG7700 series                           _privet._tcp         local
+ (null) IPv6 Canon MG7700 series                           Web Site             local
+ (null) IPv6 Canon MG7700 series                           _canon-bjnp1._tcp    local
+ (null) IPv6 Canon MG7700 series                           _privet._tcp         local

I'm curious to why the network interface column is showing (null) and whether there's a way to actually show the proper interface (wlan0, eth0, etc.)

答案1

得分: 1

您之所以在网络接口上看到(null),是因为容器在一个隔离的网络命名空间中运行,它无法访问主机接口。

您可以通过在主机网络命名空间中运行(使用--net=host,这要求您放弃-p选项),从而让容器能够访问主机网络环境,来解决这个问题。

至少在我的测试中,在这两种情况下似乎都不需要运行一个--privileged容器。

英文:

You're seeing (null) for the network interface because the container is running in an isolated network namespace -- it doesn't have any access to the host interfaces.

You could resolve this by running in the host network namespace (--net=host, which requires you to drop the -p option), which gives the container access to the host network environment.

At least in my testing, running a --privileged container doesn't appear to be necessary in either situation.

huangapple
  • 本文由 发表于 2023年6月29日 10:33:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76577734.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定