Set DNS options during docker build

Viewed 42202

Due to local network configuration I have to add --dns and --dns-search options to my docker run commands like so:

docker run --dns XX.XX.1.1 --dns-search companydomain -t mycontainer

However docker build doesn't have the same options. Is there a way to specify these options during build?

2 Answers

Dockerfile-based solution

You can also fix the DNS lookup problem on a per RUN-command level:

RUN echo "nameserver XX.XX.1.1" > /etc/resolv.conf && \ 
    echo "search companydomain" >> /etc/resolv.conf && \    
    command_depending_on_dns_resolution

Keep in mind: This will only change the DNS resolution behaviour for this one RUN command, as changes to the /etc/resolv.conf are not persistent (I could not find any official reference for this behaviour beside from a comment from of one of the core Docker engineers Brian Goff).

Related