【问题标题】:docker can't build because of alpine error由于高山错误,docker无法构建
【发布时间】:2019-05-11 14:54:18
【问题描述】:

您好,我正在尝试构建一个 docker,Docker 文件看起来像这样。

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

错误看起来像

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

一个月前它还不错。由于对 Docker 的了解有限,我无法弄清楚导致错误的原因。快速谷歌搜索得到了这两个链接:link1link2 但它们都没有工作。

【问题讨论】:

  • 永远不要从最新构建!始终标记适合您的版本。我说的是阿尔卑斯山的形象。只需将标签从最新更改为一周前的标签,构建可能会顺利进行。也不要把这么多 RUN 命令串在一起,这样会更容易调试哪一个失败。
  • 我也尝试过 FROM alpine 3.7/3.6/3.5 等,但没有任何效果。

标签: docker alpine


【解决方案1】:

使用标志“--network host”构建 docker 解决了这个问题。这是link

【讨论】:

  • 你拯救了我的一天
【解决方案2】:

行:

WARNING: Ignoring http://dl-cdn.alpinelinux.org/alpine/v3.8/main/x86_64/APKINDEX.tar.gz: could not connect to server (check repositories file)

基本上说你要么离线,要么 alpinelinux repo 已关闭。我在互联网上找不到任何关于它的信息,但过去发生过几次。或者它可能是您和 CDN 之间某处的网络问题。

您可以随时从http://dl-cdn.alpinelinux.org/alpine/MIRRORS.txt 中选择自己的镜像并进行如下设置:

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

(根据你的版本更改v3.8


正如@emix 所指出的,你永远不应该使用:latest 标签作为你的基础镜像。使用例如3.8,或者你需要的包版本。

【讨论】:

    【解决方案3】:

    另一个修复 -

    我将8.8.8.8 添加到我的/etc/resolv.conf 并重新启动了docker 守护进程。它为我解决了这个问题。

    【讨论】:

      【解决方案4】:

      这种错误通常是由于某些网络问题而发生的。

      尝试使用 https 镜像而不是 http。

      RUN sed -i -e 's/http:/https:/' /etc/apk/repositories
      

      【讨论】:

      • 唯一有效的解决方案。如果您的防火墙阻止 http 站点,则此方法有效。
      【解决方案5】:

      如果您能够手动下载文件,请尝试重新启动您的 docker 服务。它对我有用..

      【讨论】:

        【解决方案6】:

        为标题提供更通用的故障排除答案。在另一个容器中测试您的 docker 命令。这可能是另一个您不介意破坏的正在运行的容器,或者最好是一个基本容器(在本例中为 alpine),您可以在其中在 shell 上运行 Dockerfile 命令。可能不是原始问题中网络问题的解决方案,但在其他情况下很好。

        apk 错误消息并不总是最有用的。看看下面的例子:

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

        顺便说一句,https://pkgs.alpinelinux.org/packages 是查找 Alpine 软件包名称的好地方,这将修复上述示例。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2018-01-14
          • 1970-01-01
          • 1970-01-01
          • 2014-06-25
          • 1970-01-01
          • 2017-01-31
          • 1970-01-01
          相关资源
          最近更新 更多