docker repo resolving error during image build ERR

2019-07-10 02:35发布

问题:

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"]

回答1:

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.