简体   繁体   中英

Docker : ERROR: unsatisfiable constraints

Im trying to build docker image example from https://docs.docker.com/compose/gettingstarted/ . And I got this error

Building web
Step 1/9 : FROM python:3.7-alpine
 ---> e854017db514
Step 2/9 : WORKDIR /code
 ---> Using cache
 ---> e15b6e62d8af
Step 3/9 : ENV FLASK_APP app.py
 ---> Using cache
 ---> 759c4bc8b254
Step 4/9 : ENV FLASK_RUN_HOST 0.0.0.0
 ---> Using cache
 ---> 6d40793f3089
Step 5/9 : RUN apk add --no-cache gcc musl-dev linux-headers
 ---> Running in 5e40bd670f1b
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.11/community/x86_64/APKINDEX.tar.gz
WARNING: Ignoring http://dl-cdn.alpinelinux.org/alpine/v3.11/main/x86_64/APKINDEX.tar.gz: Permission denied
WARNING: Ignoring http://dl-cdn.alpinelinux.org/alpine/v3.11/community/x86_64/APKINDEX.tar.gz: Permission denied
ERROR: unsatisfiable constraints:
  gcc (missing):
    required by: world[gcc]
  linux-headers (missing):
    required by: world[linux-headers]
  musl-dev (missing):
    required by: world[musl-dev]
ERROR: Service 'web' failed to build: The command '/bin/sh -c apk add --no-cache gcc musl-dev linux-headers' returned a non-zero code: 3

This is my Dockfile

FROM python:3.7-alpine
WORKDIR /code
ENV FLASK_APP app.py
ENV FLASK_RUN_HOST 0.0.0.0
RUN apk add --no-cache gcc musl-dev linux-headers
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY . .
CMD ["flask", "run"]

Can enyone help me solve this error? Thank All !!!

Did the package you want to install move to a different registry?

Sometimes the packages that are being installed are moved from different registry branches. The default Docker Alpine image only has certain registries set. Adding additional registries expands your installation options (YMMV); I can't speak to the stability, security, and or risks associated with different registry branches. This thread helped me.

Failed Attempt & Error Message:

❯ docker run -it alpine sh                                                                                                                                                                 
/ # apk update
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
v3.12.0-175-g8b3334c57c [http://dl-cdn.alpinelinux.org/alpine/v3.12/main]
v3.12.0-178-gb27c83e867 [http://dl-cdn.alpinelinux.org/alpine/v3.12/community]
OK: 12749 distinct packages available
/ # apk add cowsay
ERROR: unsatisfiable constraints:
  cowsay (missing):
    required by: world[cowsay]
/ # 

  1. Our first clue from the output
ERROR: unsatisfiable constraints:
       cowsay (missing):
       required by: world[cowsay]
  1. Second Clue from the output

earlier in the log

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

Solutioning

  1. Search on DuckDuckGo for package <package name>

Which type of memory am I using?

  • The answer is found in clue # 2. x86_64

On the page for the packages select the proper link. so in my case:

Reading the information on that page I see that under Download the binary for this package is in presently part of

  • http://dl-cdn.alpinelinux.org/alpine/edge/testing/x86_64/cowsay-3.04-r0.apk

Comparing this to clue #2, I see that the alpine container is not referencing the registry with the binary I want to install.

Success & TL;DR;

Adding a package previously not found to alpine by adding additional registry to docker alpine container.

I'll add the registry that I need to find the package I want to install (step #3). In the code block below see that the third registry matches the initial part of the URL from the research done in part #3. I don't want to replace the existing registries (clue #2) so I set those again. I don't know if this is necessary or not but I did it anyway.

$ docker run -it alpine sh
/# apk update && apk add cowsay \
        --update-cache \
        --repository https://alpine.global.ssl.fastly.net/alpine/edge/community \
        --repository https://alpine.global.ssl.fastly.net/alpine/edge/main \
        --repository https://dl-3.alpinelinux.org/alpine/edge/testing
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
v3.12.0-175-g8b3334c57c [http://dl-cdn.alpinelinux.org/alpine/v3.12/main]
v3.12.0-178-gb27c83e867 [http://dl-cdn.alpinelinux.org/alpine/v3.12/community]
OK: 12749 distinct packages available
fetch https://dl-3.alpinelinux.org/alpine/edge/testing/x86_64/APKINDEX.tar.gz
fetch https://alpine.global.ssl.fastly.net/alpine/edge/main/x86_64/APKINDEX.tar.gz
fetch https://alpine.global.ssl.fastly.net/alpine/edge/community/x86_64/APKINDEX.tar.gz
(1/3) Installing libbz2 (1.0.8-r1)
(2/3) Installing perl (5.30.3-r2)
(3/3) Installing cowsay (3.04-r0)
Executing busybox-1.31.1-r16.trigger
OK: 43 MiB in 17 packages
/ #

Dockerfile example

FROM alpine
RUN apk update && apk add cowsay \
        --update-cache \
        --repository https://alpine.global.ssl.fastly.net/alpine/edge/community \
        --repository https://alpine.global.ssl.fastly.net/alpine/edge/main \
        --repository https://dl-3.alpinelinux.org/alpine/edge/testing
CMD ["cowsay", "hi stackoverflow"]

After building this file:

 ❯ docker run cowsay                                                                                                                                                                        [13:13:45]
 __________________ 
< hi stackoverflow >
 ------------------ 
        \   ^__^
         \  (oo)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM