PermissionError:[Errno 13] 权限被拒绝:'/manage.py'
问题描述
我正在尝试在 docker-composer
中运行以下命令,以使用 django-admin
启动项目:
I am trying to run the following command in docker-composer
, to start project with django-admin
:
docker-compose run app sh -c "django-admin startproject app ."
这会产生错误:
Traceback (most recent call last):
File "/usr/local/bin/django-admin", line 10, in <module>
sys.exit(execute_from_command_line())
File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.7/site-packages/django/core/management/commands/startproject.py", line 20, in handle
super().handle('project', project_name, target, **options)
File "/usr/local/lib/python3.7/site-packages/django/core/management/templates.py", line 155, in handle
with open(new_path, 'w', encoding='utf-8') as new_file:
PermissionError: [Errno 13] Permission denied: '/manage.py'
Dockerfile如下:
The Dockerfile is as follows:
FROM python:3.7-alpine
MAINTAINER anubrij chandra
ENV PYTHONUNBUFFERED 1
COPY ./requirements.txt /requirements.txt
RUN pip install -r /requirements.txt
RUN mkdir /app
COPY ./app /app
RUN adduser -D dockuser
USER dockuser
我的docker-compose.yml
:
version: "3"
services:
app:
build:
context: .
ports:
- "8000:8000"
volumes:
- ./app:/app
command: >
sh -c "python manage.py runserver 0.0.0.0:8000"
我应用了 这个 Stack Overflow 线程,但它没有工作.
I applied the solution suggested in this Stack Overflow thread, but it didn't work.
我使用的是 Ubuntu 18.04.
I'm using Ubuntu 18.04.
解决方案
在你的 dockerfile
中,你指向一个新用户 dockuser
.
In your dockerfile
, you are pointing to a new user dockuser
.
RUN adduser -D dockuser
USER dockuser
因此,您的容器将以用户 dockuser
开始,该用户似乎没有适当的权限来运行 /manage.py
.
Hence your container will start with user dockuser
which don't seems to have proper permissions to run /manage.py
.
你可以
- 删除上面提到的您创建并指向的行
dockuser
.
或
- 在/manage.py 文件的 dockerfile 中使用
chown
和chmod
命令为用户dockuser
提供适当的权限.
- provide appropriate permission to user
dockuser
usingchown
andchmod
commands in your dockerfile for /manage.py file.
我已经回答了类似的问题这里.
I have answered such similar question here.
相关文章