简体   繁体   English

Docker:错误:不可满足的约束

[英]Docker : ERROR: unsatisfiable constraints

Im trying to build docker image example from https://docs.docker.com/compose/gettingstarted/ .我正在尝试从https://docs.docker.com/compose/gettingstarted/构建 docker 图像示例。 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这是我的 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?您要安装的 package 是否移动到不同的注册表?

Sometimes the packages that are being installed are moved from different registry branches.有时正在安装的软件包是从不同的注册表分支中移动的。 The default Docker Alpine image only has certain registries set.默认的 Docker Alpine 映像仅设置了某些注册表。 Adding additional registries expands your installation options (YMMV);添加额外的注册表会扩展您的安装选项 (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我们从 output 获得的第一条线索
ERROR: unsatisfiable constraints:
       cowsay (missing):
       required by: world[cowsay]
  1. Second Clue from the output 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>在 DuckDuckGo 上搜索package <package name>

Which type of memory am I using?我使用的是哪种类型的 memory?

  • The answer is found in clue # 2. x86_64答案在线索# 2.x86_64

On the page for the packages select the proper link.在包装 select 的页面上,正确的链接。 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阅读该页面上的信息,我看到在Download the binary for this package is in now 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.将此与线索 #2 进行比较,我看到 alpine 容器没有使用我要安装的二进制文件引用注册表。

Success & TL;DR;成功 & TL;DR;

Adding a package previously not found to alpine by adding additional registry to docker alpine container.通过向 docker alpine 容器添加额外的注册表,将以前未找到的 package 添加到 alpine。

I'll add the registry that I need to find the package I want to install (step #3).我将添加我需要查找我想要安装的 package 的注册表(步骤 #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.在下面的代码块中,可以看到第三个注册表与第 3 部分中所做研究的 URL 的初始部分匹配。 I don't want to replace the existing registries (clue #2) so I set those again.我不想替换现有的注册表(线索#2),所以我再次设置它们。 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 Dockerfile 示例

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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