Docker with a new nameserver

后端 未结 2 884
广开言路
广开言路 2021-01-24 23:04

How I can add new nameserver in /etc/resolv.conf (dockerfile)?

On my dockerfile I use:

FROM ubuntu:14.04

RUN echo \"nameserver 10.111.122.1         


        
相关标签:
2条回答
  • 2021-01-24 23:36

    So, one of the ways you can add new DNS information to your container's build process is by adding some startup options to your Docker daemon. The documentation for that process reveals that the option you'll use is --dns. The location of your configuration file depends on your specific distro. On my Linux Mint machine, the file is in /etc/default/docker. On Linux Mint, look for the DOCKER_OPTS= line, and add the appropriate --dns=x.x.x.x entries to that line.

    For example, if you want to use Google's DNS, you should change that line to look like this:

    DOCKER_OPTS="--dns=8.8.4.4 --dns=8.8.8.8"
    

    Additionally, in the absense of --dns or --dns-search startup options, Docker will use the /etc/resolv.conf of the host it's running on instead.

    0 讨论(0)
  • 2021-01-24 23:48

    The DNS configuration of a Docker container may be adjusted during the creation of the container and does not need to be hard-coded in the Docker image itself.

    Passing a single DNS server to the container works by providing the --dns parameter:

    $ docker run --rm --dns=8.8.8.8 <image>
    

    You're free to provide more than one DNS server and you can also define other DNS related options like the DNS search name or common DNS options:

    $ docker run --rm --dns=8.8.8.8 --dns=8.8.4.4 --dns-search=your.search.domain --dns-opt=timeout:50 <image>
    

    If you pass cat /etc/resolv.conf as command to your container, you can easily verify that the passed DNS configuration options made it into the container's DNS configuration:

    $ docker run --rm --dns=8.8.4.4 --dns=8.8.8.8 --dns-search=your.domain.name --dns-opt=timeout:50 alpine cat /etc/resolv.conf
    
    search your.domain.name
    nameserver 8.8.4.4
    nameserver 8.8.8.8
    options timeout:50
    

    Please also refer to the docker run configuration which can be found at https://docs.docker.com/engine/reference/commandline/run/

    0 讨论(0)
提交回复
热议问题