如何使用 Dockerfile 安装 pip 包?获取权限限制错误

How to install pip packages with Dockerfile? Getting permission restrictions error

我有以下 Dockerfile,用于在 Google 的 App Engine 上部署 Rasa Bot 应用程序:

FROM rasa/rasa
ENV BOT_ENV=development
COPY . /var/www
WORKDIR /var/www
RUN pip install rasa phonenumbers pgeocode
#ENTRYPOINT ["rasa", "run", "-vv", "--enable-api", "actions"]
ENTRYPOINT ["rasa", "run", "-vv", "--enable-api", "--endpoints", "endpoints.yml", "--credentials", "credentials.yml", "-p", "8080"]

但是部署无法安装 phonenumberspgeocode 包,不知何故 rasa 没有问题。

我得到的错误是这样的:

ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied: '/build/lib/python3.6/site-packages/phonenumbers'
Consider using the `--user` option or check the permissions.

The command '/bin/sh -c pip install rasa phonenumbers pgeocode' returned a non-zero code: 1
ERROR
ERROR: build step 0 "gcr.io/cloud-builders/docker" failed: step exited with non-zero status: 1

我已经尝试按照建议使用 --user,在其他一些问题中,我看到了建议使用 sudo-H 标志的答案,但这也失败了,使用不同的错误提示 sudo 无法识别。

如果我删除这 2 个失败的包,我的应用程序会运行,但它无法执行需要这些包的某些操作。

知道如何解决这个问题吗?

谢谢!

您正在使用 rasa/rasa 基本映像,这就是 rasa 已经安装或安装成功的原因。

documentation for this image 建议使用 --no-cache-dir 标志:

RUN pip install --no-cache-dir jupyter

您还可以尝试 运行 您的 Dockerfile 命令作为 root 用户,方法是:

FROM rasa/rasa
USER root

USER root 也对我有用。对于未来的人,不要忘记按照 http://redhatgov.io/workshops/security_containers/exercise1.2/

即: 用户根 ... 用户 1001(或您想要的任何用户)