0

I have problem running any command requiring internet connection within my Dockerfile script (like calling apt-get install xyz), probably due to DNS problems.

I've already read this thread and added --dns 8.8.8.8 --dns 8.8.4.4 to DOCKER_OPTS. Unfortunately, it didn't help at all, still having issues connecting.

The only solution that works so far is to add the following line to my Dockerfile:

RUN 'echo nameserver 8.8.8.8 > /etc/resolv.conf'

It works, but it's cluttering the Dockerfile a little bit. I also tried to edit /etc/resolv.conf on my main machine, but it didn't help.

Any suggestions? I'm running Ubuntu 14.04, kernel 3.13.0-35

// edit:

Here's the gradle script to generate Dockerfile:

task createDockerfile(type: Dockerfile) {
    dependsOn build
    destFile = project.file('build/Dockerfile')
    from 'java:8'
    volume '/tmp'
    runCommand 'echo nameserver 8.8.8.8 > /etc/resolv.conf'
    runCommand 'apt-get update'
    runCommand 'apt-get install -y rabbitmq-server'
    runCommand 'service rabbitmq-server start'
    addFile 'libs/notification-bc-*.jar', 'notification-bc.jar'
    runCommand 'bash -c "touch /notification-bc.jar"'
    entryPoint 'java', '-jar', '/notification-bc.jar'
}

and the resulting Dockerfile iteslf:

FROM java:8
VOLUME ["/tmp"]
RUN echo nameserver 8.8.8.8 > /etc/resolv.conf
RUN apt-get update
RUN apt-get install -y rabbitmq-server
RUN service rabbitmq-server start
ADD libs/notification-bc-*.jar notification-bc.jar
RUN bash -c "touch /notification-bc.jar"
ENTRYPOINT ["java", "-jar", "/notification-bc.jar"]
Community
  • 1
  • 1
slnowak
  • 1,839
  • 3
  • 23
  • 37
  • can you show your Dockerfile ? do you always do `apt-get update && apt-get install -y xxx`? – user2915097 May 19 '15 at 19:28
  • In my docker script? Yes, I do. I'll edit my question and paste it. It's actually a gradle script, but function names are equivalent to docker commands. – slnowak May 19 '15 at 19:29
  • I have tested your Dockerfile without your `RUN echo nameserver...`and it has worked fine until the line `ÀDD...` that failed as I do not have the required file. I have Ubuntu 14.04 – user2915097 May 19 '15 at 20:08
  • You were able to install rabbitmq package? Could you show me your /etc/resolv.conf? – slnowak May 19 '15 at 21:16
  • I find it hard to believe `RUN echo nameserver 8.8.8.8 > /etc/resolv.conf`has any effect, as /etc/resolv.conf is mounted from the host which should overwrite your change. See https://docs.docker.com/articles/networking/ – Adrian Mouat May 19 '15 at 22:05
  • Try removing the `RUN` line and trying again. – Adrian Mouat May 19 '15 at 22:12
  • Already tried a few times, this is the only working solution... – slnowak May 19 '15 at 22:20
  • What does the error message say when you build from Dockerfile? Can you post it. Try also running `docker images`, get the image ID from the "incompleted" images, run a container from that image ID and do the troubleshooting from inside the container. – Daniel t. May 19 '15 at 22:23
  • Yes I was able to install rabbitmq, "Step 4 : RUN service rabbitmq-server start ---> Running in 1a286b7f5977 Starting message broker: rabbitmq-server. ---> 3e07183ccfcb Removing intermediate container 1a286b7f5977 Step 5 : ADD libs/notification-bc-*.jar notification-bc.jar INFO[0061] No source files were specified", my /etc/resolv.conf `nameserver 127.0.1.1` – user2915097 May 20 '15 at 03:48
  • sinowak; I tested this myself and I really don't believe your RUN command does anything. What version of Docker are you using and which storage driver? – Adrian Mouat May 20 '15 at 08:56
  • Docker version 1.7.0-dev, build 5e06332 How can I chcek storage driver? – slnowak May 20 '15 at 09:29

1 Answers1

0

I found the same problem. And the fix for me on Linux was to put the --dns 8.8.8.8 fix in the system service docker.service. On the "ExecStart=/usr/bin/dockerd" line add --dns 8.8.8.8. So it should look like

ExecStart=/usr/bin/dockerd  --dns 8.8.8.8

You can find this file by looking at

systemctl info docker.service

on CentOS. When I added this and then reloaded the configuration and restarted the service everything was working.

$ systemctl daemon-reload
$ systemctl restart docker.service

If you want more information I threw it in a blog post here

  • 1
    Thanks for your answer, and also for mentioning the linked blog is yours. I do however suggest you take a read of [How not to be a spammer](http://stackoverflow.com/help/promotion) to understand how the site views this kind of linking. – CalvT Apr 12 '17 at 14:17
  • This solution did not resolve my DNS issues. – Giszmo Apr 03 '21 at 16:31