docker can't build because of alpine error
Asked Answered
M

12

59

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.

Michealmicheil answered 10/12, 2018 at 16:55 Comment(2)
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.Ferrol
I have also tried FROM alpine 3.7/3.6/3.5 etc. But nothing worked.Michealmicheil
M
114

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

Michealmicheil answered 2/1, 2019 at 7:58 Comment(5)
Apparently this is invalid for Windows usersUpthrow
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.Upthrow
Remember to put --network host somewhere in the front. docker build --network host -t go/helloworld:1 -f Dockerfile.oneDermatology
Using the above throw error - Sending build context to Docker daemon 12.87MB Error response from daemon: only admin users can specify host network modeWireman
How do I do this with docker-compose if I already have an internal network with bridge driver?Schubert
M
32

-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"]
}
Misfit answered 17/3, 2022 at 0:30 Comment(3)
Yep, that was the trick.Mareah
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.Hedda
Works perfectly on Windows. Don't forget to restart Docker Desktop.Latanya
A
15

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

Argile answered 8/4, 2022 at 14:26 Comment(1)
The simplest and work solution!Kakemono
D
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.

Demount answered 10/12, 2018 at 19:57 Comment(1)
Do you mean to add the above RUN cmd in our DockerfileWireman
H
8

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
Horror answered 14/8, 2021 at 5:30 Comment(4)
The only solution that worked. This works if your firewall is blocking http sites.Understate
The reverse worked for me. Replacing https with http.Skied
where use this command? in Dockerfile?Allyson
yes, you should use it in Dockerfike. before update repositories, change addresses from https to http by that sed command.Horror
C
5

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

Conover answered 30/4, 2023 at 9:12 Comment(0)
B
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.

Barmecidal answered 24/5, 2021 at 5:41 Comment(0)
W
2

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

Wilden answered 5/8, 2020 at 10:57 Comment(0)
S
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.

Spoilsman answered 27/11, 2020 at 14:17 Comment(0)
C
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.

Chlori answered 28/11, 2022 at 8:23 Comment(0)
P
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.

Pellegrino answered 30/12, 2022 at 18:41 Comment(0)
R
-2

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

Rhynchocephalian answered 23/3, 2023 at 17:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.