【问题标题】:Potential docker permission issue is causing pillow to say it's not installed, although it is潜在的 docker 权限问题导致枕头说它没有安装,尽管它是
【发布时间】:2020-04-22 11:08:06
【问题描述】:

Following This Tutorial

基本上我的问题是,当我尝试运行某个命令时,我得到一个权限错误。尽管没有立即产生影响,但这最终会影响我工作流程的其他部分。

运行时:

RUN pip install --upgrade pip
RUN pip install --no-cache /wheels/*

我明白了:

WARNING: The directory '/home/app/.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.

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

然后奇怪的是,我跑了:

docker-compose -f docker-compose.prod.yml exec app python manage.py migrate --noinput

我收到一个奇怪的错误提示:

estimate_creator.TopLevelService.service_image: (fields.E210) Cannot use ImageField because Pillow is not installed.
        HINT: Get Pillow at https://pypi.org/project/Pillow/ or run command "python -m pip install Pillow".

我确实安装了 Pillow,并且在我的开发环境中没有问题。

不过没问题,我会安装它。所以我跑了:

docker-compose -f docker-compose.prod.yml exec app python -m pip install Pillow

然后看看:

Requirement already satisfied: Pillow in /usr/local/lib/python3.8/site-packages (6.2.1)

好的...然后我尝试卸载并重新安装我得到这个回溯:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/shutil.py", line 780, in move
    os.rename(src, real_dst)
PermissionError: [Errno 13] Permission denied: '/usr/local/lib/python3.8/site-packages/PIL/' -> '/tmp/pip-uninstall-opp36exc'

你认为发生了什么?

我已尝试将 dockerfile 的最后一行注释掉,这会使用户无效。

###########
# BUILDER #
###########

# pull official base image
FROM python:3.8.0-alpine as builder

# set work directory
WORKDIR /usr/src/app

# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# install psycopg2 dependencies
RUN apk update \
    && apk add postgresql-dev gcc python3-dev musl-dev zlib

#########
# Pillow #
#########

RUN apk add build-base python-dev py-pip jpeg-dev zlib-dev

#########
# Pillow #
#########

# install dependencies
COPY ./requirements.txt .
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/wheels -r requirements.txt


#########
# FINAL #
#########

# pull official base image
FROM python:3.8.0-alpine

# create directory for the app user
RUN mkdir -p /home/app

# create the app user
RUN addgroup -S app && adduser -S app -G app

# create the appropriate directories
ENV HOME=/home/app
ENV APP_HOME=/home/app/web
RUN mkdir $APP_HOME
WORKDIR $APP_HOME

# install dependencies
RUN apk update && apk add libpq
COPY --from=builder /usr/src/app/wheels /wheels
COPY --from=builder /usr/src/app/requirements.txt .
RUN pip install --upgrade pip
RUN pip install --no-cache /wheels/*

# copy project
COPY . $APP_HOME

# chown all the files to the app user
RUN chown -R app:app $APP_HOME

# change to the app user
USER app

【问题讨论】:

  • 你好,我也在关注这个教程。你解决了这个问题吗?
  • @MahmudulHassan 你可以看到我接受了下面的问题。

标签: django docker permissions docker-compose python-imaging-library


【解决方案1】:

我在一个类似的项目中遇到了同样的问题。 为了找到原因,我尝试从 PIL (from PIL import Image) 导入 Image,然后从错误消息中追踪丢失的库。 这个 Dockerfile 就是结果。 (不过,我使用的是基于 Debian 的映像,对于 alpine,您必须自己找到相应的库)

RUN apt-get update && apt-get install -y \
    libjpeg-dev \
    zlib1g-dev \
    libpng-dev \
    libopenjp2-7-dev \
    libtiff-dev \

【讨论】:

    猜你喜欢
    • 2016-04-03
    • 2015-12-13
    • 1970-01-01
    • 1970-01-01
    • 2013-01-11
    • 1970-01-01
    • 2021-06-26
    • 2018-04-22
    • 2014-07-13
    相关资源
    最近更新 更多