53

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.

2
  • 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, 2018 at 17:49
  • 1
    I have also tried FROM alpine 3.7/3.6/3.5 etc. But nothing worked.
    – BhanuKiran
    Dec 10, 2018 at 18:32

12 Answers 12

103

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

5
  • 1
    Apparently this is invalid for Windows users Jan 29, 2022 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. Jan 29, 2022 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, 2022 at 7: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 6, 2022 at 11:15
  • How do I do this with docker-compose if I already have an internal network with bridge driver?
    – Mischa
    Apr 26 at 8:29
31

-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"]
}
3
  • 2
    Yep, that was the trick.
    – Picard
    Apr 26, 2022 at 12:51
  • 1
    Thanks, this solution worked for me. But weirdly, after some days/weeks the problem came back. I have to restart docker, and then it works again. Sep 19, 2022 at 19:20
  • 1
    Works perfectly on Windows. Don't forget to restart Docker Desktop. Apr 20 at 10:14
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

0
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.

1
  • Do you mean to add the above RUN cmd in our Dockerfile
    – dev_khan
    Jun 6, 2022 at 11:16
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
4
  • 2
    The only solution that worked. This works if your firewall is blocking http sites. Jan 4, 2022 at 10:07
  • 1
    The reverse worked for me. Replacing https with http.
    – prayagupa
    Dec 8, 2022 at 22:20
  • where use this command? in Dockerfile?
    – CodeBy
    Jul 20 at 20:00
  • yes, you should use it in Dockerfike. before update repositories, change addresses from https to http by that sed command.
    – Lord Johar
    Jul 21 at 21:12
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.

3

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

2

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

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.

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.

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.

-1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.