在Docker容器中如何使root可写/ etc / hosts? [英] How can I make /etc/hosts writable by root in a Docker Container?
问题描述
我无法编辑/ etc / hosts(但是需要我正在开发的一些软件)。文件的自动编辑(通过sudo或root)将其显示在只读文件系统上。手动(vim)编辑文件表示其只读,我无法以root身份保存更改(文件权限为rw为owner(root))。
我可以修改其他文件并在/ etc中添加文件。
是否有原因?
我可以更改Docker配置以允许编辑/ etc / hosts吗?
谢谢
更新 2014-09
请参阅@Thomas答案:
/ etc / hosts现在可以从Docker 1.2写入。
原始答案
同时可以使用此黑客
< a href =https://unix.stackexchange.com/questions/57459/how-can-i-override-the-etc-hosts-file-at-user-level> https://unix.stackexchange.com / questions / 57459 / how-can-i-override-the-etc-hosts-file-at-user-level
在您的Dockerfile中:
添加your_hosts_file / tmp / hosts
RUN mkdir -p - / lib-override&& cp /lib/x86_64-linux-gnu/libnss_files.so.2 / lib-override
运行perl -pi -e:/ etc / hosts:/ tmp / hosts:g'/ lib-override / libnss_files .so.2
ENV LD_LIBRARY_PATH / lib-override
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 file says its on a read only file system. Manual (vim) edit of the file says its read-only and I'm unable to save changes as root (file permissions are rw for owner (root)).
I can however modify other files and add files in /etc.
Is there some reason for this?
Can I change the Docker configuration to allow edit of /etc/hosts?
thanks
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
这篇关于在Docker容器中如何使root可写/ etc / hosts?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!