python - 在 Docker 容器 Django 中使用 Pip 安装软件包时权限被拒绝

标签 python django docker ubuntu pip

我无法在我的 docker 容器中安装包,请告诉我如何解决这个问题。
警告:

WARNING: The directory '/home/app/.cache/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you should use sudo's -H flag.


错误:
ERROR: Could not install packages due to an OSError: [Errno 13] Permission denied: '/home/app'
Check the permissions.
Dockerfile:
FROM python:3
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

WORKDIR /app
EXPOSE 8000

COPY ./core/ /app/
COPY ./scripts /scripts

RUN pip install --upgrade pip
COPY requirements.txt /app/
RUN pip install -r requirements.txt && \
    adduser --disabled-password --no-create-home app && \
    mkdir -p /vol/web/static && \
    mkdir -p /vol/web/media && \
    chown -R app:app /vol && \
    chmod -R 755 /vol && \
    chmod -R +x /scripts

USER app

CMD ["/scripts/run.sh"]
容器内的命令:
pip install django-storages

最佳答案

在我的例子中,我通过添加 -u 0 使用 root 用户安装了这个包。它告诉 docker 以 root 用户身份进入。

docker exec -u 0 -it mycontainer bash

关于python - 在 Docker 容器 Django 中使用 Pip 安装软件包时权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70850687/

相关文章:

python - 现代 glTranslate 和 glRotate 的替代品是什么?

ssl - 登录 artifactory docker registry 时出现隧道连接失败错误

lxc - 在不指定命令的情况下使用 Docker 启动容器

python - 数据库设计正确

templates - 撰写文件Docker中的模板语法

python - 当新数据到来时,如何重新训练 pyspark 中保存的线性回归 ML 模型

python - 将列表从 python 移动到 C

python - XML 到 CSV 转换器

python - Django 模型在后端数据库更新时更新

保存后的 MySQL + Django : No obj. id()