【发布时间】:2020-04-22 11:08:06
【问题描述】:
基本上我的问题是,当我尝试运行某个命令时,我得到一个权限错误。尽管没有立即产生影响,但这最终会影响我工作流程的其他部分。
运行时:
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