Narasimha Prasanna HN
Narasimha Prasanna HN

Reputation: 662

Get MAC address of host inside a docker container

I'm looking for an efficient way to get the MAC address of host inside a docker container. The docker container will not run with host network enabled and I don't want to supply the MAC address as an ENV variable. There would be a program ( preferably C++ or Python code ) that runs inside the docker container. The program would write the MAC address to a file. The MAC address will be the true MAC address of the host's network device. The docker will have a Ubuntu operating system. Any ways of achieving this?

Upvotes: 1

Views: 2350

Answers (1)

J-Jacques M
J-Jacques M

Reputation: 1118

Try this

ifconfig -a | grep -Po 'HWaddr \K.*$') > /path/you/choose/host_mac_address

When running you docker run

    docker run -v /path/you/choose:/app container

Inside your app just need to open the file located /app/host_mac_address

Make all of this better when you got the idea

All of this will be better using an ENV variable (but you dont want this solution)

Upvotes: 2

Related Questions