有人可以帮助我吗? 我不知道为什么会发生此错误,我授予 django 文件应用程序权限 在 chown -R appuser /app
更多细节: 我使用 docker-compose 构建 和 docker-compose up 我的项目树: https://i.ibb.co/WKwWFgw/aaa.png 我的文件:
Dockerfile:
# For more information, please refer to https://aka.ms/vscode-docker-python
FROM python:3.9-alpine3.13
EXPOSE 8000
ENV PATH="/scripts:${PATH}"
# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE=1
# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED=1
# Install pip requirements
COPY requirements.txt .
RUN apk add --no-cache jpeg-dev zlib-dev
RUN apk add --update --no-cache --virtual .tmp gcc libc-dev linux-headers && apk add postgresql-dev gcc python3-dev musl-dev \
&& pip install Pillow && apk add gcc musl-dev python3-dev libffi-dev openssl-dev cargo
# more pip
RUN pip install psycopg2
#end more pip
RUN pip install --upgrade pip
RUN python -m pip install -r requirements.txt
RUN apk del .tmp
COPY /app /app
WORKDIR /app
COPY ./scripts /scripts
RUN chmod +x /scripts/*
# Creates a non-root user with an explicit UID and adds permission to access the /app folder
# For more info, please refer to https://aka.ms/vscode-docker-python-configure-containers
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
USER appuser
# During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug
# File wsgi.py was not found in subfolder: 'default_docker_project'. Please enter the Python path to wsgi file.
ENTRYPOINT [ "/scripts/entrypoint.sh" ]
入口点.sh #!/bin/sh
设置 -e
python manage.py migrate --noinput
python manage.py collectstatic --noinput
python manage.py makemigrations --noinput
gunicorn --bind 0.0.0.0:8000 --log-level=DEBUG app.wsgi
要求.txt
django==3.1.1,<4.0.0
gunicorn==20.0.4,<29.0.0
whitenoise>=5.0.1,<5.1
django-db-prefix==1.0.5,<1.2.0
django-taggit>=1.4.0,<1.9.9
django-crispy-forms>=1.11.2,<1.99.9
Markdown==3.3.4
social-auth-app-django==4.0.0
应用内应用 urls.py
if settings.DEBUG == True:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
settings.py
"""
Django settings for app project.
Generated by 'django-admin startproject' using Django 3.2.
For more information on this file, see
https://docs.djangoproject.com/en/3.2/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""
from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get(str(os.getenv('SECRET_KEY')), 'changeme')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.getenv('DEBUG', default=True)
ALLOWED_HOSTS = []
ALLOWED_HOSTS_ENV = os.environ.get('ALLOWED_HOSTS')
if ALLOWED_HOSTS_ENV:
ALLOWED_HOSTS.extend(ALLOWED_HOSTS_ENV.split(','))
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
# user APPS
"blog.apps.BlogConfig",
"taggit",
# "django.contrib.sites",
# "django.contrib.sitemaps",
"account.apps.AccountConfig",
# "social_django",
# "django_extensions",
"images.apps.ImagesConfig",
"crispy_forms",
]
INSTALLED_APPS = ['django_db_prefix', ] + INSTALLED_APPS
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
]
ROOT_URLCONF = 'app.urls'
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [os.path.join(BASE_DIR, "templates")],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]
WSGI_APPLICATION = 'app.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases
DB_PREFIX = "db_krzyzak21_space_"
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': os.getenv('NAME'),
'USER': os.getenv('USER'),
'PASSWORD': os.getenv('PASSWORD'),
'HOST': os.getenv('HOST'),
'PORT': os.getenv('PORT'),
}
}
# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/
STATIC_URL = '/static/'
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
# Default logging
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'default': {
'format': '[DJANGO] %(levelname)s %(asctime)s %(module)s '
'%(name)s.%(funcName)s:%(lineno)s: %(message)s'
},
},
'handlers': {
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': './logs/debug.log',
},
},
'loggers': {
'django': {
'handlers': ['file'],
'level': 'DEBUG',
'propagate': True,
},
},
}
# More
LOGIN_URL = "login"
LOGOUT_URL = "logout"
LOGIN_REDIRECT_URL = "profile"
LOGOUT_REDIRECT_URL = "base"
AUTHENTICATION_BACKENDS = [
"django.contrib.auth.backends.ModelBackend",
"account.authentication.EmailAuthBackend",
"social_core.backends.facebook.FacebookOAuth2",
]
CRISPY_TEMPLATE_PACK = "bootstrap4"
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
# EMAILS
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = os.getenv('EMAIL_HOST_USER'),
EMAIL_HOST_PASSWORD = os.getenv('EMAIL_HOST_PASSWORD'),
EMAIL_PORT = 587
EMAIL_USE_TLS = True
# SOCIAL
SOCIAL_AUTH_FACEBOOK_KEY = os.getenv('SOCIAL_AUTH_FACEBOOK_KEY'),
SOCIAL_AUTH_FACEBOOK_SECRET = os.getenv('SOCIAL_AUTH_FACEBOOK_SECRET'),
我的错误: 它发生在所有文件管理员
krzyzak21@DESKTOP-PBESVTN:/mnt/m/WorkspaceDjango/krzyzak21space_docker$ docker-compose up
Starting krzyzak21space_docker_app ... done
Attaching to krzyzak21space_docker_app
app_1 | Operations to perform:
app_1 | Apply all migrations: admin, auth, blog, contenttypes, sessions, taggit
app_1 | Running migrations:
app_1 | No migrations to apply.
app_1 | Traceback (most recent call last):
app_1 | File "/app/manage.py", line 22, in <module>
app_1 | main()
app_1 | File "/app/manage.py", line 18, in main
app_1 | execute_from_command_line(sys.argv)
app_1 | File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
app_1 | utility.execute()
app_1 | File "/usr/local/lib/python3.9/site-packages/django/core/management/__init__.py", line 395, in execute
app_1 | self.fetch_command(subcommand).run_from_argv(self.argv)
app_1 | File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 330, in run_from_argv
app_1 | self.execute(*args, **cmd_options)
app_1 | File "/usr/local/lib/python3.9/site-packages/django/core/management/base.py", line 371, in execute
app_1 | output = self.handle(*args, **options)
app_1 | File "/usr/local/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 194, in handle
app_1 | collected = self.collect()
app_1 | File "/usr/local/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 118, in collect
app_1 | handler(path, prefixed_path, storage)
app_1 | File "/usr/local/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 355, in copy_file
app_1 | self.storage.save(prefixed_path, source_file)
app_1 | File "/usr/local/lib/python3.9/site-packages/django/core/files/storage.py", line 52, in save
app_1 | return self._save(name, content)
app_1 | File "/usr/local/lib/python3.9/site-packages/django/core/files/storage.py", line 291, in _save
app_1 | os.chmod(full_path, self.file_permissions_mode)
app_1 | PermissionError: [Errno 1] Operation not permitted: '/app/staticfiles/admin/js/actions.js'
krzyzak21space_docker_app exited with code 1