我无法在我的 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/