Skip to content

Instantly share code, notes, and snippets.

@jumarko
Created December 14, 2015 07:16
Show Gist options
  • Save jumarko/7ab32baf3527a2f06ce7 to your computer and use it in GitHub Desktop.
Save jumarko/7ab32baf3527a2f06ce7 to your computer and use it in GitHub Desktop.
Custom script for modification to /etc/hosts. Providing custom /etc/hosts when building the image doesn't work because docker overwrites /etc/hosts when starting the container. Running simple "sed -i" inside entrypoint run script doesn't work because sed is not able to just overwrite /etc/hosts (sed: cannot rename /etc/sedl8ySxL: Device or resou…
#!/usr/bin/env bash
# clean-up /etc/hosts if multiple hostname points to localhost - required for Mac OS using "--add-host 'localhost:10.0.2.2'"
localhostCount=`grep localhost /etc/hosts | wc -l`
if [[ $localhostCount -gt 2 ]];then
cat /etc/hosts | sed '/127.0.0.1.*/d' > hosts.tmp
cat hosts.tmp > /etc/hosts
rm hosts.tmp
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment