简体   繁体   中英

How to pass host ip address to docker in mac OS?

I am working on Linux machine and I wrote an script to pass local host IP address to docker container by passing an parameter It works fine for ubuntu. will the same script run on mac OS and work as expected (pass IP address of local host to docker container)?

docker run -t -i -e "DOCKER_HOST=$(ip -4 addr show eth0 | grep -Po 'inet \K[\d.]+')" $IMAGE_NAME

在OSX上使用此命令行:

docker run -it -e "DOCKER_HOST=$(ifconfig en0 | awk '/ *inet /{print $2}')" $IMAGE_NAME

On mac, you will be using a VM, so you might want to pass the IP of the docker machine you have declared:

https://docs.docker.com/installation/images/mac_docker_host.svg

(image from " docker on Mac OS X ")

eval $(docker-machine env default)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM