4

Using Ubuntu 16.04 and docker 18.03.1-ce

In a Dockerfile I have:

RUN curl -k -o app.jar -kfSL https://mynexus:9006/repository/legacy/1.0.2/app.jar

But when I build that with:

sudo docker build -t myimage .

I get:

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0curl: (6) Could not resolve host: mynexus
The command '/bin/sh -c curl -k -o app.jar -kfSL https://mynexus:9006/repository/legacy/1.0.2/app.jar' returned a non-zero code: 6

If I run the exact same command line from a terminal it works fine:

$ curl -k -o app.jar -kfSL https://mynexus:9006/repository/legacy/1.0.2/app.jar
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 3613k  100 3613k    0     0  1413k      0  0:00:02  0:00:02 --:--:-- 1413k

Why can I curl that file from command line but not from the DockerFile?

u123
  • 15,603
  • 58
  • 186
  • 303
  • Possible duplicate of [Name resolution failing during docker build](https://stackoverflow.com/questions/51786057/name-resolution-failing-during-docker-build) – Tai Nov 21 '18 at 15:34

1 Answers1

1

You can see the curl error message when running the last commited image from the build with curl command:

docker run -it --rm lastCommitedImageHash curl -k -o app.jar -kfSL https://mynexus:9006/repository/legacy/1.0.2/app.jar

I had the same problem last week - curl worked directly from host but not when ran during build from Dockerfile.

Restart of Docker daemon helped to me.

I haven't found what was the reason of that state. It was on the machine which is also as a Kubernetes master and I did Kubernetes cluster upgrade last week and probably this was the source of that problem.

Another cause of that problem in your case can be if you have mynexus hostname defined only in the /etc/hosts file on the host machine and then it is unknown for the running container during the build.

cgrim
  • 4,890
  • 1
  • 23
  • 42
  • Aha if I specify the IP address it works. I have tried to restart docker daemon multiple times but that did not help. mynexus is not in the /etc/hosts file – u123 May 24 '18 at 13:04
  • Then you can look here: https://stackoverflow.com/questions/24151129/docker-network-calls-fail-during-image-build-on-corporate-network And add {"dns": ["yourDnsServerIp"] } into the /etc/docker/daemon.json file and restart docker daemon to apply changes. – cgrim May 24 '18 at 13:18
  • Running curl with `-fL` fixed it for me. – phyatt Jan 30 '20 at 15:51