Skip to content

Instantly share code, notes, and snippets.

@lalyos
Last active May 28, 2017 14:25
Show Gist options
  • Save lalyos/9525120 to your computer and use it in GitHub Desktop.
Save lalyos/9525120 to your computer and use it in GitHub Desktop.
hacking docker /etc/hosts file to writable

Right now when you start a docker instance, you can change the /etc/hosts file. Previously i was workarounding this limitation with dnsmasq, but it seems to havyweight.

I found an alternate solution on stackowerflow which simply hacks libnss_files.so, by replaces all /etc/hosts reference with /tmp/hosts, then puts the hacked library to LD_LIBRARY_PATH

hack

Here is the sligthly modified version for centos:

cp /etc/hosts /tmp/hosts
#vi /tmp/hosts
mkdir -p -- /lib-override && cp /lib64/libnss_files.so.2 /lib-override

sed -i.bak 's:/etc/hosts:/tmp/hosts:g' /lib-override/libnss_files.so.2
export LD_LIBRARY_PATH=/lib-override
cp /etc/hosts /tmp/hosts
#vi /tmp/hosts
mkdir -p -- /lib-override && cp /lib64/libnss_files.so.2 /lib-override
sed -i.bak 's:/etc/hosts:/tmp/hosts:g' /lib-override/libnss_files.so.2
export LD_LIBRARY_PATH=/lib-override
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment