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
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