无法在 docker 容器中编辑/etc/resolv.conf [英] unable to edit /etc/resolv.conf in docker container

查看:65
本文介绍了无法在 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

我尝试了 echosed.使用 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 my/myawesome:latest

但我有兴趣让 dockerFile 正常工作.

but I am interested in getting dockerFile working.

推荐答案

这是设计使然./etc/resolv.conf 被 docker 引擎用来处理服务发现.文档说明如下:

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.confDHCP 稍后.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:

这篇关于无法在 docker 容器中编辑/etc/resolv.conf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆