Skip to content

Instantly share code, notes, and snippets.

@myw
Last active January 10, 2017 11:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save myw/318b99cdb4b7166b118222bfcf1b99e3 to your computer and use it in GitHub Desktop.
Save myw/318b99cdb4b7166b118222bfcf1b99e3 to your computer and use it in GitHub Desktop.
Add DNS Search domains to the Docker For Mac VM
#!/usr/bin/env bash
# add-dns-search-domain.sh - Tell the Docker for Mac VM to add any search domains
# from the host machine's resolv.conf to its own
# resolv.conf. Must be run every time networking is
# restarted on the Docker VM, or the docker VM
# is rebooted
# Find the search domains from the host's resolv.conf
resolvfile=/etc/resolv.conf
tempfile=$(mktemp)
grep search $resolvfile > $tempfile
# Docker HyperKit VM TTY socker
tty_socket=${DOCKER_TTY_SOCKET:-~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/tty}
# XXX any commands sent to the tty socket are followed by a timeout to give
# the tty time to respond
timeout='sleep 0.5'
echo -e '\04' > $tty_socket && $timeout
# XXX Must be logged out to work!
# Log In as Root
echo 'root' > $tty_socket && $timeout
# Can't copy files directly, so have to cat them through stdout
echo 'export VM_TEMPFILE=$(mktemp)' > $tty_socket && $timeout
echo 'cat <<EOF > $VM_TEMPFILE' > $tty_socket && $timeout
cat $tempfile > $tty_socket && $timeout
echo 'EOF' > $tty_socket && $timeout
# Append the tempfile to the resolver file
echo "cat \$VM_TEMPFILE >> $resolvfile" > $tty_socket && $timeout
# Cleanup
echo 'rm -f $VM_TEMPFILE' > $tty_socket && $timeout
echo -e '\04' > $tty_socket
rm -f $tempfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment