我运行docker compose命令并获取"PermissionDenied";错误大约两个月前,我使用了同样的代码,它运行得很好。我在互联网上搜索过,但解决方案帮不了什么忙。
docker-compose run --rm app sh -c "django-admin startproject app ."
它给了我一个错误:
Traceback (most recent call last):
File "/py/bin/django-admin", line 8, in <module>
sys.exit(execute_from_command_line())
File "/py/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/py/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/py/lib/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/py/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/py/lib/python3.9/site-packages/django/core/management/commands/startproject.py", line 21, in handle
super().handle('project', project_name, target, **options)
File "/py/lib/python3.9/site-packages/django/core/management/templates.py", line 160, in handle
with open(new_path, 'w', encoding='utf-8') as new_file:
PermissionError: [Errno 13] Permission denied: '/app/manage.py'
我的Dockerfile是:
FROM python:3.9-alpine3.13
LABEL maintainer="Kananappdeveloper"
ENV PYHTONUNBUFFERED 1
COPY ./requirements.txt /tmp/requirements.txt
COPY ./requirements.dev.txt /tmp/requirements.dev.txt
COPY ./app /app
WORKDIR /app
EXPOSE 8000
ARG DEV=false
RUN python -m venv /py &&
/py/bin/pip install --upgrade pip &&
/py/bin/pip install -r /tmp/requirements.txt &&
if [ $DEV = "true" ];
then /py/bin/pip install -r /tmp/requirements.dev.txt ;
fi &&
rm -rf /tmp &&
adduser
--disabled-password
--no-create-home
django-user
ENV PATH="/py/bin:$PATH"
USER django-user
我的操作系统是Ubuntu 22.04
提前谢谢。
使用命令ll
检查文件夹app
创建者的用户名。然后找出用户的用户id。
然后使用在Docker中创建具有该id的用户
adduser
-u $
--disabled-password
--no-create-home
django-user
然后建造docker。