簡體   English   中英

在 Docker 容器中下載 Pip 包

[英]Downloading Pip Packages in Docker Container

我正在嘗試在 Dockerfile/容器中使用 Pip3 下載 Pika package。 我當前的 Dockerfile 看起來像這樣:

FROM rabbitmq

#install Python
RUN apt-get update &&\
    apt-get install -y \
    python3-pip

#Create new user
RUN useradd -ms /bin/bash user
USER user
WORKDIR /home/user

#Install Pika
RUN pip3 install pika

RUN mkdir videos

COPY . .

CMD ["python3", "ffmpeg.py"]

output 我得到聲稱它一切正常並且一切都安裝成功。 但是容器由於錯誤立即退出:

Traceback (most recent call last):
File "ffmpeg.py", line 1, in <module>
import pika, sys, os
ModuleNotFoundError: No module named 'pika'

如果我將 SSH 放入容器並使用以下命令手動下載 Pika:

pip3 install pika

然后運行 python 文件,一切正常。 但由於某種原因,Dockerfile 無法使用完全相同的命令安裝它。

到目前為止,我已經嘗試了此頁面上的幾乎所有解決方案

我正在運行 Ubuntu 版本 20.04.1 和 Docker 版本 20.10.2。

還有什么我可以嘗試的嗎?

所以我想我找到了解決辦法。 我將我的 Dockerfile 更改為在創建新用戶之前安裝我的 Pika。 所以它現在看起來像這樣:

FROM rabbitmq

#install Python
RUN apt-get update &&\
    apt-get install -y \
    python3-pip

#Install Pika
RUN python3 -m pip install pika

#Create new user
RUN useradd -ms /bin/bash user
USER user
WORKDIR /home/user

RUN mkdir videos

COPY . .

CMD ["python3", "ffmpeg.py"]

這解決了我無法識別 Pika 的問題,但現在在構建圖像時,我得到了這個:

The directory '/var/lib/rabbitmq/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.

圖像仍在構建並且文件現在運行,所以不確定新錯誤有什么樣的影響。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM