Last active
March 26, 2018 19:37
-
-
Save andrius/e81b04a83571bcb9f421066733f8ce30 to your computer and use it in GitHub Desktop.
IP address of docker host (mac) in shell scripts. Only works with #docker for #macos
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Tested on alpine linux | |
# Thanks to `docker.for.mac.localhost` (or `docker.for.mac.host.internal`) | |
# featured in https://docs.docker.com/docker-for-mac/networking/#i-want-to-connect-from-a-container-to-a-service-on-the-host, | |
# it's possible to access host (mac) services | |
# mac_ip will set IP address (MAC_IP) of mac visible from docker container and | |
# return code (0 = IP found, 1 = not found) | |
mac_ip() { | |
MAC_IP=`ping -c 1 docker.for.mac.host.internal 2>/dev/null | grep ' from ' | awk -F ' \|:' '{print $4}'` | |
[ "${MAC_IP}" != "" ] && return 0 || return 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment