首页 > 解决方案 > 如何在 Docker 容器中使用 sudo -H 执行 pip 以激活缓存?

问题描述

为了减轻以下警告,

WARNING: The directory '/home/jovyan/.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 may want sudo's -H flag.

我通常会运行 pip 作为

sudo -H pip install -r requirements.txt

现在我在 Dockerfile 中执行 pip:

FROM python3.7-slim
USER root
COPY requirements.txt /app/requirements.txt
RUN pip install -U setuptools pip \
    && pip install -r /app/requirements.txt

我将如何激活-H标志?

还有其他方法可以激活缓存吗?

标签: pythondockerpip

解决方案


推荐阅读