gpt4 book ai didi

django - 潜在的 docker 权限问题导致枕头说它没有安装,尽管它是

转载 作者:行者123 更新时间:2023-12-02 19:52:44 25 4
gpt4 key购买 nike

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

最佳答案

我在类似的项目中遇到了同样的问题。
为了找到原因,我尝试从 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 \

关于django - 潜在的 docker 权限问题导致枕头说它没有安装,尽管它是,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59586133/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com