V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
eric13517
V2EX  ›  Docker

主机修改 resolv.conf 文件后,怎么让已启动的 docker 容器生效。

  •  
  •   eric13517 · 2020-03-13 11:50:01 +08:00 · 3783 次点击
    这是一个创建于 1498 天前的主题,其中的信息可能已经有所发展或是发生改变。
    最近一个项目在用 docker swarm,根据用户的要求,需要动态去设置主机的 /etc/resolv.conf 文件,加上以下内容:
    search domain.local
    nameserver xxx.xxx.xxx.xxx
    设置后,在主机内就可以 ping 通 xxx.domain.local 这样的域名。

    但这个设置对已启动的容器无效,容器内默认的 resolv.conf 文件是如下内容:
    nameserver 127.0.0.11
    options ndots:0
    这时 ping 不通域名。

    如果 docker 或主机重启后,容器内的 resolv.conf 文件会自动加上如下一行:
    search domain.local
    这时就可以 ping 通域名了。

    因为容器比较多,不想改个文件就去重启 docker 或主机,有没有什么方法能让主机修改 resolv 文件后,对已启动的容器也立即生效?
    4 条回复    2020-03-13 17:58:16 +08:00
    coolloves
        1
    coolloves  
       2020-03-13 13:52:21 +08:00
    映射进去就可以吧
    rrfeng
        2
    rrfeng  
       2020-03-13 13:55:38 +08:00
    -v/tmp/resolv.conf:/etc/resolv.conf

    映射进去没错,但内外别共享同一个免得带来不必要的麻烦。
    eric13517
        3
    eric13517  
    OP
       2020-03-13 14:12:51 +08:00
    docker 内部有个 DNS:127.0.0.11 ,可以供容器之间互相访问,原来容器内部的 resolv.conf 配的是这个 DNS。
    所以不能把主机的 resolv.conf 映射到容器里吧
    julyclyde
        4
    julyclyde  
       2020-03-13 17:58:16 +08:00
    libc 的行为
    只读一次那个文件
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1146 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 18:23 · PVG 02:23 · LAX 11:23 · JFK 14:23
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.