How can I make /etc/hosts writable by root in a Docker Container?

后端 未结 4 591
花落未央
花落未央 2021-01-31 18:43

I\'m new to using docker and am configuring a container.
I am unable to edit /etc/hosts (but need to for some software I\'m developing). Auto-edit (via sudo or root) of the

4条回答
  •  误落风尘
    2021-01-31 19:31

    UPDATE 2014-09

    See @Thomas answer:

    /etc/hosts is now writable as of Docker 1.2.

    Original answer

    You can use this hack in the meanwhile

    https://unix.stackexchange.com/questions/57459/how-can-i-override-the-etc-hosts-file-at-user-level

    In your Dockerfile:

    
    ADD your_hosts_file /tmp/hosts
    RUN mkdir -p -- /lib-override && cp /lib/x86_64-linux-gnu/libnss_files.so.2 /lib-override
    RUN perl -pi -e 's:/etc/hosts:/tmp/hosts:g' /lib-override/libnss_files.so.2
    ENV LD_LIBRARY_PATH /lib-override
    

提交回复
热议问题