When building a docker image, I have a curl command which pulls down a file as such:
RUN curl -L http://files.mycompany.com/ -o file.war
files.mycompany.com is a server accessable only from within the company network. I can reach this server from my host machine, but not from within the docker container if I use the name (IP works fine).
This works: RUN ping google.com
This works: RUN ping 10.3.2.1
(IP of files.mycompany.com)
This does not work: RUN ping files.mycompany.com
(translates the name to another IP than if I ping the same server from the host machine)
Something is not setup correctly on my machine since building the container from another dev computer on the same network works fine. It's like the docker interface does not receive the DNS records from the local network?
I am running Ubuntu 17.04.
docker run --network="host" Alternatively you can run a docker container with network settings set to host . Such a container will share the network stack with the docker host and from the container point of view, localhost (or 127.0.0.1 ) will refer to the docker host.
DNS services Containers that use the default bridge network get a copy of this file, whereas containers that use a custom network use Docker's embedded DNS server, which forwards external DNS lookups to the DNS servers configured on the host.
Connect a container to a network when it starts You can also use the docker run --network=<network-name> option to start a container and immediately connect it to a network.
Docker containers take DNS IPs from the host machine, which is managed by systemd-resolve . Those IPs themselves are the cloud provider's DNS.
Do this in your host:
cat /etc/resolv.conf
If you see something like 127.0.0...
, it means that the DNS config that your host uses is a daemon that listen to localhost. Docker can't tell your container to use the same DNS because the container has it's own localhost, so docker defaults to the Google DNS (8.8.8.8). You can confirm that doing this inside the container: cat /etc/resolv.conf
I recommend you to follow steps here, so edit your /etc/docker/daemon.json
, and put this:
{"dns": ["your_dns_server_ip"]}
Note about /etc/default/docker
: this file is not used anymore in latest Ubuntu versions. Instead, create the json file that I've pointed out. See the docs: /etc/docker/daemon.json
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With