问题
Is it possible to get MAC address of the host machine from Docker container and write it in a text file?
回答1:
docker inspect <container name or id> |grep MacAddress|tr -d ' ,"'|sort -u
or inside the container:
ifconfig -a
ifconfig is part of the 'net-tools' linux pkg and this is good way to enter the running container:
nsenter -t $(docker inspect --format '{{ .State.Pid }}' <container name or id> ) -m -u -i -n -p -w
回答2:
Use docker inspect to pull MacAddress and redirect the results to a file. For example, try this on a container named my-container. This uses range (from the Go template package) to find MacAddress:
docker inspect -f '{{range .NetworkSettings.Networks}}{{.MacAddress}}{{end}}' my-container > /path/file.txt
If that doesn't work, first try viewing the metadata available for my-container:
docker inspect my-container
Find MacAddress in those results. Then create a docker inspect command that uses the docker json template function to pull the value from that specific json path. The path to MacAddress may vary, so here's an example that instead uses Status:
docker inspect -f "{{json .State.Health.Status}}" my-container > /path/file.txt
来源:https://stackoverflow.com/questions/43275289/getting-mac-address-from-docker-container