python - 我在构建 Python3.6-buster 容器时收到 'apt-get upgrade' 命令失败错误

标签 python python-3.x docker debian-buster

昨天,当我在 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/

相关文章:

python - 如何有效地连接 numpy 中的许多 arange 调用?

python - 使用 css 选择器查找标签,但不查找其后代

python - 有条件计算的最pythonic方法是什么?

python - 在 if 和 elif 上出错

python - 列表中每个单词的首字母大写;栏全部大写的单词

python - 如何修复错误 "_core.QgsProcessingException: There were errors executing the algorithm."

python - 哪一种数据加载方法最适合性能?

linux - Docker 从部分图像中理解

docker - 使用用户注册表动态生成子域

linux - nginx/apache重定向vps上docker容器上的输出端口