我花了一整天的时间对该问题进行故障排除,希望我只是想念解决方案,因为我是Docker的新手。这是在Windows计算机上。在一个空文件夹中设置一个新项目时,/ app我应该运行:
docker-compose run app sh -c "django-admin.py startproject app ."
我得到的错误
Traceback (most recent call last):
File "/usr/local/bin/django-admin.py", line 5, in <module>
management.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 316, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 353, 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 1] Operation not permitted: '/app/manage.py'
Dockerfile:
FROM python:3.7-alpine
MAINTAINER Ryan
ENV PYTHONUNBUFFERED 1
COPY ./requirements.txt /requirements.txt
RUN pip install -r /requirements.txt
RUN mkdir /app
RUN chmod a+rwx /app
WORKDIR /app
COPY ./app /app
RUN adduser -D user
RUN chown user:user /app
RUN chmod +x /app
USER user
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"
cap_add:
- NET_ADMIN
- NET_RAW
network_mode: "host"
我在这里找到的其他类似文章中添加了一些内容,例如docker文件中的chown和chmod行,但似乎没有什么不同。我还尝试了从docker-compose , PermissionError: [Errno 13] Permission denied: '/manage.py'之类的链接中找到的内容,但是没有运气。我什至完全按照链接帖子中一个人的建议删除了用户行,但这没什么不同。
每次更改后,我都会运行:
docker build --tag recipeimage . --no-cache
docker-compose build --no-cache
我的想法是,如果我在不清除缓存的情况下解决此问题,也许更改不会结束,但这也许不是必需的。
无论哪种方式,任何帮助都将是惊人的,我什至都不知道如何解决这个问题以进一步解决问题,因为我的docker经验非常有限。
如果有帮助,我的文件夹结构如下:
'Parent folder'
/app (currently empty)
docker-compose.yml
Dockerfile
requirements.txt