'docker can't build because of alpine error

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.



Solution 1:[1]

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.

Solution 2:[2]

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

Solution 3:[3]

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

Solution 4:[4]

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.

Solution 5:[5]

Another fix -

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

Solution 6:[6]

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

Solution 7:[7]

I think I've done all what was proposed here, without any success.

  1. Change http to https
  2. Use the --network host trick
  3. Add 8.8.8.8 in resolv.conf
  4. Use a mirror

See my last build

I can download on that machine the index without any problem. But when using Docker (with or without gitlab-runner), it just fails. It works beautifully on another machine on the same network with the same architecture (armv7).

If my first instruction is RUN wget https://mirrors.ircam.fr/pub/alpine/v3.15/main/armv7/APKINDEX.tar.gz I get ---> Running in 19a0630d633a wget: bad address 'mirrors.ircam.fr'

Solution 8:[8]

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

Solution 9:[9]

Probably your best option here is to mute that particular error.

Muted items represent issues that are not currently worth investigating. In the Muted state:

  • The item won't appear on the Dashboard
  • If the item occurs again, it will remain Muted
  • Occurrences count for billing purposes

If you have an item that you consider a non-issue, or otherwise don't plan to do anything about soon, you can Mute it so it stays out of sight.

Muted items are still indexed, searchable, etc. and can be changed back to Active at any time. For this reason, occurrences of Muted items do count for billing purposes. If you need to reduce your usage, you should set a rate limit or filter it before it is sent to Rollbar.

You may also be interested in this page in our documentation:

https://docs.rollbar.com/docs/reduce-noisy-javascript-errors

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 AymDev
Solution 2
Solution 3 Kannan Sid
Solution 4 Nagev
Solution 5 Vipul Vaibhaw
Solution 6 Lord Johar
Solution 7
Solution 8 Amin Shojaei
Solution 9