gpt4 book ai didi

docker : ERROR: unsatisfiable constraints

转载 作者:行者123 更新时间:2023-12-02 19:30:04 28 4
gpt4 key购买 nike

我正在尝试从 https://docs.docker.com/compose/gettingstarted/ 构建 docker 镜像示例。我收到了这个错误

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

这是我的 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"]

有人可以帮我解决这个错误吗?谢谢大家!!!

最佳答案

您想要安装的软件包是否已移至其他注册表?

有时,正在安装的软件包是从不同的注册表分支移动的。默认的 Docker Alpine 镜像仅设置了某些注册表。添加额外的注册表可以扩展您的安装选项 (YMMV);我无法谈论与不同注册表分支相关的稳定性、安全性和/或风险。 This thread helped me.

失败的尝试和错误消息:

❯ 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. 我们从输出中得到的第一条线索
ERROR: unsatisfiable constraints:
cowsay (missing):
required by: world[cowsay]
  • 输出中的第二条线索
  • 日志前面

    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

    解决方案

  • 在 DuckDuckGo 上搜索 package <package name>
  • 我使用哪种类型的内存?

    • 答案可以在线索#2中找到。x86_64

    在包页面上选择正确的链接。所以就我而言:

    阅读该页面上的信息,我发现在下载下,该软件包的二进制文件目前位于

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

    将其与线索 #2 进行比较,我发现 alpine 容器没有使用我想要安装的二进制文件引用注册表。

    成功 & TL;DR;

    通过向 docker alpine 容器添加额外的注册表,将以前未找到的包添加到 alpine。

    我将添加查找我想要安装的软件包所需的注册表(步骤#3)。在下面的代码块中,可以看到第三个注册表与第 3 部分中完成的研究中的 URL 的初始部分相匹配。我不想替换现有的注册表(线索#2),所以我再次设置了它们。我不知道这是否有必要,但我还是这么做了。

    $ 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 示例

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

    构建此文件后:

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

    关于 docker : ERROR: unsatisfiable constraints,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61968808/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com