Access host machine details from inside Docker container [closed]

泪湿孤枕 提交于 2019-12-13 06:44:25

问题


I would like to know the way to get host machine details especially the MAC address from inside Docker container.


回答1:


Maybe you can approach this problem different way. Eg. pass information you need from host to container via environment variables.

docker run -e HOST_MAC=$(ifconfig -a | grep -Po 'HWaddr \K.*$') image

This requires you to change how you run a container, however it's probably the cleanest method of solving this.




回答2:


It will depend on your host system, since you didn't give any information I'm just going to assume CentOS

In this article it shows how you can get that info from /prove on the host system. So, if you mount /prove into your container you should be able to read the right file and pull out your info.

This doesn't seem secure though, and I recommend against it.




回答3:


You have many options.

Аnother option is

docker run -it -v /var/log/:/log --name vmaccess busybox /bin/sh
grep eth0 /log/dmesg

[    2.307760] e1000 0000:00:03.0 eth0: (PCI:33MHz:32-bit) 08:00:27:98:dc:aa
[    2.307783] e1000 0000:00:03.0 eth0: Intel(R) PRO/1000 Network Connection
[    4.186427] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
[    8.985277] IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready



回答4:


One other way is to use --net=host while starting the container.

$# ifconfig -a | grep -Po 'HWaddr \K.*$'

00:00:00:00:00:00  
9c:b6:54:1d:80:4b  
48:5a:b6:67:9e:11   

$# docker run --net=host -it ubuntu:14.04 bash

$# ifconfig -a | grep -Po 'HWaddr \K.*$'

00:00:00:00:00:00  
9c:b6:54:1d:80:4b  
48:5a:b6:67:9e:11  


来源:https://stackoverflow.com/questions/36980618/access-host-machine-details-from-inside-docker-container

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!