无法在Docker容器中编辑

无法在Docker容器中编辑

本文介绍了无法在Docker容器中编辑/etc/resolv.conf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的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:

如果要覆盖/重新配置某些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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 06:59