无法在Docker容器中编辑/etc/resolv.conf [英] unable to edit /etc/resolv.conf in docker container
问题描述
我想在我的Docker容器的 /etc/resolv.conf
中添加一个域条目。
I want to add a domain entry to /etc/resolv.conf
of my docker container.
这是我的dockerFile
Here is my dockerFile
FROM tomcat:8.0.20-jre7
VOLUME /tmp
#RUN sed -i "s|search local|domain com.example.com|g;" /etc/resolv.conf
RUN echo "domain com.example.com" >> /etc/resolv.conf
# Expose ports.
EXPOSE 8080
我都尝试了 echo
和 sed
。
与 sed
,在构建期间出现错误。
I tried both echo
and sed
.
with sed
, I get error during build.
sed:无法重命名/ etc / sed6LcoES:设备或资源繁忙
但使用 echo
容器构建并成功运行。
但是,当我进入容器时,我没有在 /etc/resolv.conf
中看到我的域。
but with echo
container build and run successfully.
however, when I get into container, I do not see my domain added in /etc/resolv.conf
.
为什么不起作用?
注意:我已经通过传递了 dns-search
运行参数期间
NOTE: I have got dns-search
working by passing during run argument
docker run -p 8080:8080 --dns-search = com.example.com -d --name myawesome我/ myawesome:latest
但我有兴趣使dockerFile工作。
but I am interested in getting dockerFile working.
推荐答案
这是设计使然。 docker引擎使用 /etc/resolv.conf
处理服务发现。文档指出以下内容:
This is by design. /etc/resolv.conf
is used by docker engine to handle service discovery. Documentation states the following:
Docker如何为每个容器提供主机名和DNS配置,而不必使用主机名构建自定义映像写在里面?它的诀窍是在容器内的三个关键/ etc文件上覆盖可以写入新信息的虚拟文件…这种安排使Docker可以在主机接收到新的配置后,在所有容器上执行诸如使resolv.conf保持最新状态等聪明的事情。稍后进行DHCP。 Docker如何在容器内维护这些文件的确切详细信息可能会从一个Docker版本更改为另一个Docker版本,因此您应自己保留文件,而使用以下Docker选项。
How can Docker supply each container with a hostname and DNS configuration, without having to build a custom image with the hostname written inside? Its trick is to overlay three crucial /etc files inside the container with virtual files where it can write fresh information … This arrangement allows Docker to do clever things like keep resolv.conf up to date across all containers when the host machine receives new configuration over DHCP later. The exact details of how Docker maintains these files inside the container can change from one Docker version to the next, so you should leave the files themselves alone and use the following Docker options instead.
如果要覆盖/重新配置某些DNS设置,请在容器启动过程中使用-dns
参数。查看更多详细信息:
If you want to override/reconfigure some dns settings, use --dns
parameters during container starting. See more details:
- Configure DNS in Docker
这篇关于无法在Docker容器中编辑/etc/resolv.conf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!