52

Hi I am trying build a docker and Docker file looks like this.

FROM alpine

LABEL description "Nginx + uWSGI + Flask based on Alpine Linux and managed by Supervisord"

# Copy python requirements file
COPY requirements.txt /tmp/requirements.txt

RUN apk add --no-cache \
    python3 \
    bash \
    nginx \
    uwsgi \
    uwsgi-python3 \
    supervisor && \
    python3 -m ensurepip && \
    rm -r /usr/lib/python*/ensurepip && \
    pip3 install --upgrade pip setuptools && \
    pip3 install -r /tmp/requirements.txt && \
    rm /etc/nginx/conf.d/default.conf && \
    rm -r /root/.cache

# Copy the Nginx global conf
COPY nginx.conf /etc/nginx/
# Copy the Flask Nginx site conf
COPY flask-site-nginx.conf /etc/nginx/conf.d/
# Copy the base uWSGI ini file to enable default dynamic uwsgi process number
COPY uwsgi.ini /etc/uwsgi/
# Custom Supervisord config
COPY supervisord.conf /etc/supervisord.conf

# Add demo app
COPY ./app /app
WORKDIR /app

CMD ["/usr/bin/supervisord"]

Errors looks like

Sending build context to Docker daemon  250.9kB
Step 1/11 : FROM alpine
 ---> 196d12cf6ab1
Step 2/11 : LABEL description "Nginx + uWSGI + Flask based on Alpine Linux and managed by Supervisord"
 ---> Using cache
 ---> d8d38c761b8d
Step 3/11 : COPY requirements.txt /tmp/requirements.txt
 ---> Using cache
 ---> cb29eb34ca46
Step 4/11 : RUN apk add --no-cache     python3     bash     nginx     uwsgi     uwsgi-python3     supervisor &&     python3 -m ensurepip &&     rm -r /usr/lib/python*/ensurepip &&     pip3 install --upgrade pip setuptools &&     pip3 install -r /tmp/requirements.txt &&     rm /etc/nginx/conf.d/default.conf &&     rm -r /root/.cache
 ---> Running in 3d568d2620dd
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz
WARNING: Ignoring http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz: could not connect to server (check repositories file)
fetch http://dl-cdn.alpinelinux.org/alpine/v3.8/community/x86_64/APKINDEX.tar.gz
WARNING: Ignoring http://dl-cdn.alpinelinux.org/alpine/v3.8/community/x86_64/APKINDEX.tar.gz: could not connect to server (check repositories file)
ERROR: unsatisfiable constraints:
  bash (missing):
    required by: world[bash]
  nginx (missing):
    required by: world[nginx]
  python3 (missing):
    required by: world[python3]
  supervisor (missing):
    required by: world[supervisor]
  uwsgi (missing):
    required by: world[uwsgi]
  uwsgi-python3 (missing):
    required by: world[uwsgi-python3]
The command '/bin/sh -c apk add --no-cache     python3     bash     nginx     uwsgi     uwsgi-python3     supervisor &&     python3 -m ensurepip &&     rm -r /usr/lib/python*/ensurepip &&     pip3 install --upgrade pip setuptools &&     pip3 install -r /tmp/requirements.txt &&     rm /etc/nginx/conf.d/default.conf &&     rm -r /root/.cache' returned a non-zero code: 6

A month ago it was building fine. Because of the limited knowledge in Docker i couldn't to figure what's causing the error. A quick google search has resulted in these two links: link1 link2 But none of them were working.

BhanuKiran
  • 2,631
  • 3
  • 20
  • 36
  • 5
    Never build from latest! Always tag a version which is working for you. I’m speaking about the Alpine image. Just change the tag from latest to the one from the week ago and probably the build will go smoothly. Also don’t chain so many RUN commands in one, it will be easier to debug which one failed. – Mike Doe Dec 10 '18 at 17:49
  • 1
    I have also tried FROM alpine 3.7/3.6/3.5 etc. But nothing worked. – BhanuKiran Dec 10 '18 at 18:32

12 Answers12

102

Build docker with flag "--network host" solved the issue. Here is the link.

BhanuKiran
  • 2,631
  • 3
  • 20
  • 36
  • 1
    Apparently this is invalid for Windows users – Affes Salem Jan 29 '22 at 20:10
  • 1
    the docs in the link says `The host networking driver only works on Linux hosts, and is not supported on Docker Desktop for Mac, Docker Desktop for Windows, or Docker EE for Windows Server.` – Affes Salem Jan 29 '22 at 20:11
  • Remember to put `--network host` somewhere in the front. `docker build --network host -t go/helloworld:1 -f Dockerfile.one` – Rick May 16 '22 at 07:42
  • Using the above throw error - Sending build context to Docker daemon 12.87MB Error response from daemon: only admin users can specify host network mode – dev_khan Jun 06 '22 at 11:15
  • How do I do this with docker-compose if I already have an internal network with bridge driver? – Mischa Apr 26 '23 at 08:29
30

-In Ubuntu

It was a DNS error for me. By setting /etc/docker/daemon.json with,

{
  "dns": ["8.8.8.8"]
}

and then restarting docker with,

sudo service docker restart

I was able to build images again.

https://github.com/gliderlabs/docker-alpine/issues/334#issuecomment-450598069

-In Windows

C:/Users/Administrator(or any other Username)/.docker/daemon.json

And add

{
  ...,
  "dns": ["8.8.8.8"]
}
LoveCoding
  • 1,121
  • 2
  • 12
  • 33
13

Try restarting the docker service, it worked for me and others:

sudo systemctl restart docker docker.service

Thanks to: https://github.com/gliderlabs/docker-alpine/issues/334#issuecomment-408826204

Amin Shojaei
  • 5,451
  • 2
  • 38
  • 46
12

The line:

WARNING: Ignoring http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz: could not connect to server (check repositories file)

Basically says that you are either offline, or the alpinelinux repo is down. I cannot find anything about it on the internet, but it happened several times in the past. Or it can be network problem somewhere in between you and the cdn.

You can always pick mirror yourself from the http://dl-cdn.alpinelinux.org/alpine/MIRRORS.txt and setup it like so:

RUN echo http://repository.fit.cvut.cz/mirrors/alpine/v3.8/main > /etc/apk/repositories; \
    echo http://repository.fit.cvut.cz/mirrors/alpine/v3.8/community >> /etc/apk/repositories

(change the v3.8 according to you version)


Also as @emix pointed out, you should never use :latest tag for your base image. Use for example 3.8, or the one with packages versions you need.

AymDev
  • 6,626
  • 4
  • 29
  • 52
michalhosna
  • 7,327
  • 3
  • 21
  • 40
7

This kind of errors often happend due to some network problem.

Try use https mirrors instead of http.

RUN sed -i -e 's/http:/https:/' /etc/apk/repositories
Lord Johar
  • 119
  • 2
  • 7
3

Another fix -

I added 8.8.8.8 to my /etc/resolv.conf and restarted the docker daemon. It fixed this issue for me.

Vipul Vaibhaw
  • 395
  • 7
  • 15
2

If you are able to manually download the file, try restarting your docker service. It did the trick for me..

Kannan Sid
  • 21
  • 1
2

Providing a more generic troubleshooting answer for the title. Test your docker commands in another container. This could be another running container that you don't mind breaking, or preferably a base container (in this case alpine) where you can run the Dockerfile commands on the shell. Probably not a solution where the network is the issue as in the original question, but good in other cases.

The apk error messages aren't always the most useful. Take a look at the example below:

/ # apk add --no-cache influxdb-client
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz
ERROR: unsatisfiable constraints:
  influxdb-client (missing):
    required by: world[influxdb-client]
/ # 
/ # 
/ # 
/ # 
/ # apk add --no-cache influxdb
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.12/community/x86_64/APKINDEX.tar.gz
(1/1) Installing influxdb (1.8.0-r1)
Executing influxdb-1.8.0-r1.pre-install
Executing busybox-1.31.1-r19.trigger
OK: 613 MiB in 98 packages

By the way, https://pkgs.alpinelinux.org/packages is a good place to find the names of packages for Alpine, which would fix the above example.

Nagev
  • 10,835
  • 4
  • 58
  • 69
1

Using Google (8.8.8.8) or Cloudflare (1.1.1.1) DNS will suffice for most of the users.

But for Iranian(or any other region where docker is prohibited there) users, due to the sanctions, there are limits when using docker, so you may also change the registry-mirrors to a local (Iranian) mirror.

daemon.json:

{
    "dns": ["8.8.8.8"], 
    "registry-mirrors": ["https://registry.docker.ir"]
}

Another option for people in Iran is to use Shecan DNS.

daemon.json:

{
    "dns": ["185.51.200.2"], 
}


Don't forget to restart the docker service after editing the config file.

1. Linux: sudo systemctl restart docker docker.service

2. Windows: check out here for further instructions



File Location:

1. Linux: /etc/docker/daemon.json

2. Windows: C:/Users/{'USERNAME'})/.docker/daemon.json

Farhad
  • 494
  • 5
  • 20
0

In my case I had changed the /etc/docker/daemon.json and added a repository-mirrors to bypass filtering in my region and download docker images from that repo.

daemon.json:

    {
      "registry-mirrors": [
      "https://docker.somerepo.com"
     ],
      "insecure-registries": [],
      "debug": true,
      "experimental": false
    }

so that was the problem, I removed daemon.json file (or you could comment all lines in the daemon.json file) and it was fine to go and download new docker images.

Farhad
  • 494
  • 5
  • 20
0

I still ran into this problem as of dez 2022 with debian buster. Docker on Buster seems to be incompOption 2 here solved the problem for me.

Toby
  • 2,174
  • 4
  • 22
  • 32
-1

I came across same issue you might want to disable internet security or any VPN if you are connected with it.

Karan Gehlod
  • 134
  • 1
  • 9