3

I have a problem with building docker image and tried different DNS option but seems no luck.

Docker version 1.9.1, build a34a1d5

Repos are alive. For running container I used docker run --dns=192.168.1.1 -d -ti --name alpine3 alpine tag and dns works weel there.

For images I added my DNS IP 192.168.1.1 to /etc/docker/daemon.json and /etc/default/docker.io and to docker eth DNS but this didn't help.

And I restarted docker service many times and re-pulled alpine image.

I even created local repo with localhost which is reachable with path in the log during build, I can download needed file, but when I run docker build I receive errors.

doc1@ubuntu:$ docker build -t web .
Sending build context to Docker daemon 5.632 kB
Step 1 : FROM alpine
 ---> 3c82203aab43
Step 2 : MAINTAINER y0zg
 ---> Using cache
 ---> 16cc74909dc2
Step 3 : RUN echo http://localhost > /etc/apk/repositories;     echo http://nl.alpinelinux.org/alpine/v3.6/main >> /etc/apk/repositories
 ---> Using cache
 ---> b7f808daeb7b
Step 4 : RUN apk --no-cache update
 ---> Running in f6625eaa1d7d
fetch http://localhost/x86_64/APKINDEX.tar.gz
ERROR: http://localhost: could not connect to server (check repositories file)
fetch http://localhost/x86_64/APKINDEX.tar.gz
WARNING: Ignoring http://localhost/x86_64/APKINDEX.tar.gz: could not connect to server (check repositories file)
fetch http://nl.alpinelinux.org/alpine/v3.6/main/x86_64/APKINDEX.tar.gz
ERROR: http://nl.alpinelinux.org/alpine/v3.6/main: temporary error (try again later)
2 errors; 11 distinct packages available

Here is dockerfile

doc1@ubuntu:$ cat Dockerfile 
FROM alpine
MAINTAINER y0zg
RUN echo http://localhost > /etc/apk/repositories; \
    echo http://nl.alpinelinux.org/alpine/v3.6/main >> /etc/apk/repositories
RUN apk --no-cache update
ADD counter.rb counter.rb
EXPOSE 4567
ENTRYPOINT ["ruby","counter.rb"]
OKie
  • 53
  • 1
  • 6
  • A container has its own localhost, different from the one of your machine. Try this instead: `http://172.17.0.1` – Robert Oct 29 '17 at 01:48
  • Thanks @Robert, I used my local machine IP where docker daemon is running and it helped to fetch needed artefacts. I wonder why containers cannot fetch artefacts from the Internet, any idea how to solve this during docker build without workarounds I have? – OKie Oct 29 '17 at 09:12
  • Well, the problem is definitely with DNS. This dockerfile allows to fetch artefacts from the Internet repos. Any idea how to fix this? `doc1@ubuntu:~/dockerexamples/docker2web$ cat Dockerfile FROM alpine MAINTAINER y0zg RUN sed -i -e 's/dl-cdn.alpinelinux.org/147.75.32.21/' /etc/apk/repositories RUN echo http://147.75.32.21/alpine/v3.6/main >> /etc/apk/repositories RUN apk update && apk add ruby ADD counter.rb counter.rb EXPOSE 4567 ENTRYPOINT ["ruby","counter.rb"] doc1@ubuntu:~/dockerexamples/docker2web$ ` – OKie Oct 29 '17 at 09:33
  • The docker version is really too old. They have changed how implement DNS handling. Can you upgrade? – Robert Oct 29 '17 at 12:48
  • I tried on Centos and it works like a charm, this is definitely versions bug, thanks – OKie Oct 29 '17 at 12:58

1 Answers1

0

It's DNS issue you can solve it by using the following steps:

1) Find your DNS ip using below command

nmcli dev show | grep 'IP4.DNS'

IP4.DNS[1]: 192.168.0.1

2) Create a file in the desktop which name is deamon.json and file has below data: { "dns": ["192.168.0.1", "8.8.8.8"] }

note: replace that ip 192.168.0.1 to your dns ip

3) Go that directory /etc/docker/ in your system and paste file deamon.json that you just created

4) Then restart your docker/your system, it will solve your issue.

qiAlex
  • 4,290
  • 2
  • 19
  • 35
Saad Qamar
  • 1,039
  • 9
  • 9