昨天,当我在 python:3.6-buster 镜像上构建 Python Flask 应用程序时,没有出现任何问题。但今天我收到了这个错误。
Calculating upgrade...
The following packages will be upgraded: libgnutls-dane0 libgnutls-openssl27 libgnutls28-dev libgnutls30 libgnutlsxx28
5 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 2859 kB of archives.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] Abort.
ERROR: Service 'gateway' failed to build: The command '/bin/sh -c apt-get upgrade' returned a non-zero code: 1
我的 Dockerfile:
FROM python:3.6-buster
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
RUN echo $TZ > /etc/timezone
RUN apt-get update
RUN apt-get upgrade
RUN apt-get -y install gcc musl-dev libffi-dev
COPY requirements.txt requirements.txt
RUN python3 -m pip install -r requirements.txt
COPY . /application
WORKDIR /application
EXPOSE 7000
我找不到任何相关问题。我猜这是关于新的更新,但我实际上不知道。对于这个问题有什么建议或解决方案吗?
最佳答案
我猜 apt
正在等待用户输入以确认升级。如果没有 hacky 解决方案,Docker 构建器无法处理这些交互式对话框。因此,它失败了。
最直接的解决方案是将 -y
标志添加到您的命令中,就像在安装命令中执行的那样。
FROM python:3.6-buster
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
RUN echo $TZ > /etc/timezone
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get -y install gcc musl-dev libffi-dev
COPY requirements.txt requirements.txt
RUN python3 -m pip install -r requirements.txt
COPY . /application
WORKDIR /application
EXPOSE 7000
但是...您真的需要更新现有的软件包吗?您的情况可能不需要这样做。此外,我可能建议您查看 Docker Best Practices编写包含 apt 命令的语句。为了保持较小的图像大小,您应该考虑将这些命令压缩在单个 RUN 语句中。此外,您应该随后删除 apt 缓存,以最大程度地减少两层之间的更改:
FROM python:3.6-buster
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
RUN echo $TZ > /etc/timezone
RUN apt-get update \
&& apt-get -y install gcc musl-dev libffi-dev \
&& rm -rf /var/lib/apt/lists/*
COPY requirements.txt requirements.txt
RUN python3 -m pip install -r requirements.txt
COPY . /application
WORKDIR /application
EXPOSE 7000
关于python - 我在构建 Python3.6-buster 容器时收到 'apt-get upgrade' 命令失败错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61084573/