gpt4 book ai didi

docker - 无法在Docker容器中编辑/etc/resolv.conf

转载 作者:行者123 更新时间:2023-12-04 17:44:22 28 4
gpt4 key购买 nike

我想将域条目添加到我的Docker容器的/etc/resolv.conf中。

这是我的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,在构建过程中出现错误。
sed: cannot rename /etc/sed6LcoES: Device or resource busy
但是使用 echo容器即可构建并成功运行。
但是,当我进入容器时,看不到 /etc/resolv.conf中添加了我的域。

为什么它不起作用?

注意:我已经通过在运行参数传递来使 dns-search工作
docker run -p 8080:8080 --dns-search=com.example.com -d --name myawesome my/myawesome:latest
但是我有兴趣让dockerFile工作。

最佳答案

这是设计使然。 docker引擎使用/etc/resolv.conf处理服务发现。文档指出以下内容:

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参数。查看更多详细信息:
  • Configure DNS in Docker
  • 关于docker - 无法在Docker容器中编辑/etc/resolv.conf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41032744/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com