无法在 docker 容器中 apt-get install(但 pip install 可以)

问题描述 投票:0回答:1

我在使用 apt-get 时遇到错误,但在 pip install 时却没有。

这是我的 dockerfile 的一部分:

FROM python:3.11-bookworm


# Set the shell to Bash
SHELL ["/bin/bash", "-c"]
RUN apt-get update && \
    apt-get install libturbojpeg


# Set the working directory
WORKDIR /app

# Copy the contents of airflow-local-env into the container
# remember to build with the righ build context
# e.g 
COPY airflow-local-env .

# Install any needed packages specified in requirements.txt excluding apache-airflow
RUN pip install --upgrade pip
RUN grep -v 'apache-airflow' requirements.txt | xargs -n 1 pip install --no-cache-dir --no-build-isolation


# Set the PYTHONPATH to include the plugins directory
ENV PYTHONPATH=$PYTHONPATH:/app/plugins

在添加

apt-get
命令之前,一切正常。现在我收到这些错误:

> [2/7] RUN apt-get update &&     apt-get install libturbojpeg:
0.227 Err:1 http://deb.debian.org/debian bookworm InRelease
0.227   407  authenticationrequired [IP: 10.12.9.140 8080]
0.289 Err:2 http://deb.debian.org/debian bookworm-updates InRelease
0.289   407  authenticationrequired [IP: 10.12.9.140 8080]
0.349 Err:3 http://deb.debian.org/debian-security bookworm-security InRelease
0.349   407  authenticationrequired [IP: 10.12.9.140 8080]
0.351 Reading package lists...
0.362 E: The repository 'http://deb.debian.org/debian bookworm InRelease' is not signed.
0.362 E: Failed to fetch http://deb.debian.org/debian/dists/bookworm/InRelease  407  authenticationrequired [IP: 10.12.9.140 8080]
0.362 E: Failed to fetch http://deb.debian.org/debian/dists/bookworm-updates/InRelease  407  authenticationrequired [IP: 10.12.9.140 8080]
0.362 E: The repository 'http://deb.debian.org/debian bookworm-updates InRelease' is not signed.
0.362 E: Failed to fetch http://deb.debian.org/debian-security/dists/bookworm-security/InRelease  407  authenticationrequired [IP: 10.12.9.140 8080]
0.362 E: The repository 'http://deb.debian.org/debian-security bookworm-security InRelease' is not signed.

在我看来,存在代理问题。但如果是这样的话,为什么

pip install
会起作用?

我已经使用

--network host
标志构建图像。此外,在我的
.docker/config.json
中,代理已配置(并且再次...pip 工作正常)。 此外,
HTTP_PROXY/HTTPS_PROXY
环境变量也已正确配置。

我真的不知道问题出在哪里。有什么想法吗?

编辑:我尝试了this答案中解释的内容(复制我的本地 apt.conf)。它有效,但我不喜欢这个解决方案。

python linux docker proxy debian
1个回答
0
投票

我将本地的

/etc/apt/apt.conf
复制到一个文件中,并将该文件复制到图像中:

COPY ./apt.conf /etc/apt/apt.conf

现在一切正常了,但我的用户和密码都在这张图片中,但我不喜欢这样。另外,因为我的其他同事无需执行任何操作即可构建映像,所以我认为我的 docker 或代理配置存在问题。接受新想法

© www.soinside.com 2019 - 2024. All rights reserved.