Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying DNS for docker build

When using the docker run command, it's possible to specify what the DNS hosts of the container should be by passing --dns <dns_server_ip> arguments.

Is there an equivalent for the docker build command? There is nothing about it in the docs, and trying it throws an error.

like image 863
Matthew Herbst Avatar asked Dec 29 '25 08:12

Matthew Herbst


1 Answers

A friend of mine suggested another solution:

use ADD to insert a /etc/resolv.conf into the container as the first build instruction. Then the container will use those settings for all future builds.

This has the benefit of being a per-container issue, so I don't need to make the change globally or start up a new VM.

like image 160
Matthew Herbst Avatar answered Jan 01 '26 16:01

Matthew Herbst