V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
eric13517
V2EX  ›  Docker

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

  •  
  •   eric13517 · Mar 13, 2020 · 4669 views
    This topic created in 2235 days ago, the information mentioned may be changed or developed.
    最近一个项目在用 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 replies    2020-03-13 17:58:16 +08:00
    sparkssssssss
        1
    sparkssssssss  
       Mar 13, 2020
    映射进去就可以吧
    rrfeng
        2
    rrfeng  
       Mar 13, 2020
    -v/tmp/resolv.conf:/etc/resolv.conf

    映射进去没错,但内外别共享同一个免得带来不必要的麻烦。
    eric13517
        3
    eric13517  
    OP
       Mar 13, 2020
    docker 内部有个 DNS:127.0.0.11 ,可以供容器之间互相访问,原来容器内部的 resolv.conf 配的是这个 DNS。
    所以不能把主机的 resolv.conf 映射到容器里吧
    julyclyde
        4
    julyclyde  
       Mar 13, 2020
    libc 的行为
    只读一次那个文件
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   6074 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 52ms · UTC 02:36 · PVG 10:36 · LAX 19:36 · JFK 22:36
    ♥ Do have faith in what you're doing.