Docker Community Forums

Share and learn in the Docker community.

DNS resolution in Dockerfile FROM instruction

docker
build
dns

(Hpcsc) #1

I have a Dockerfile to build an image to be used internally in my company like this:

FROM internal-nexus/some/base-image

In my host machine (MacOS), I have the following entry in /etc/hosts

xx.yy.zz.vv internal-nexus

If I run docker build using above Dockerfile without pulling the base image in advanced, docker takes a long time to respond and finally times out:

request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers)

If I do a docker pull in host machine and then docker build, everything is working fine, docker can pull the base image and build using Dockerfile

I tried to specify --add-host=internal-nexus:xx.yy.zz.vv during docker build but it’s not helping

My question is: how the FROM instruction resolves DNS and how to solve this issue?


(Sam) #2

docker --add-host is only during docker run command

apparently the docker daemon cannot find your local internal-nexus link.

did u add that AFTER you started the docker engine? (rebooted)

many times the docker daemon does not pickup changes


(Hpcsc) #3

hi,

I provided --add-host option to the docker build as mentioned here: https://docs.docker.com/engine/reference/commandline/build/#options

It looks something like this:

docker build --add-host=nexus-internal:xx.yy.zz.vv .

It should not be because docker not restarted either. I restarted my machine several times since that option is added


(Sam) #4

hmm… see this https://stackoverflow.com/questions/30908845/how-to-ask-docker-to-pull-from-private-repository-when-building

The image name should include the FQDN of the registry host. So if you want to FROM you must specifiy it as FROM registry_host:5000/foo/bar

so I think your case would the

from http://nexus-internal:port/some/base-image
you might still need the add host to get the ip address into build


(David Maze) #5

And to answer the OP’s question, the Docker daemon resolves the host name; AFAIK there are no command-line options that can affect this. On Docker for Mac the daemon is running in a virtual machine that’s somewhat hidden and it will not use the /etc/hosts file on the physical host.

I’d advise you to ask the group that maintains the local registry and get an internal DNS setup. It’ll save you and everyone else on your team a huge amount of ongoing hassle of exactly this sort.


(Hpcsc) #6

@dmaze thanks and yeah, you are right. I’ll ask someone to help setting up internal DNS server

@sdetweil I tried FROM http://nexus-internal:port/some/base-image but apparently it’s not valid for FROM instruction, due to http:// part