我已經關注了本教程用於使用 django、gunicorn、nginx 和 postgresql 部署 Web 應用程式。
在教程中使用空應用程式時,一切似乎都正常,但後來我嘗試使用 Django 應用程式重新創建相同的配置,並且在嘗試收集靜態檔案時收到“權限被拒絕”。
配置yml為:
version: '3.7'
services:
postgres:
image: postgres:11.2-alpine
volumes:
- database:/var/lib/postgresql/data
env_file: .env.pg
django:
build: .
command: gunicorn mysite.wsgi:application --bind 0.0.0.0:8000
volumes:
- static:/usr/src/django/static
expose:
- 8000
env_file: .env
depends_on:
- postgres
nginx:
build: ./nginx
volumes:
- static:/usr/src/django/static
ports:
- 8009:80
depends_on:
- django
volumes:
database:
static:
我執行時得到的錯誤docker-compose exec django python manage.py collectstatic --clear --noinput
是
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
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/contrib/staticfiles/management/commands/collectstatic.py", line 167, in handle
any(self.storage.listdir(destination_path))
File "/usr/local/lib/python3.7/site-packages/django/core/files/storage.py", line 315, in listdir
for entry in os.scandir(path):
PermissionError: [Errno 13] Permission denied: '/usr/src/django/static'
我嘗試在容器內執行 shell:「靜態」目錄是它應該在的位置,但我無法在其中寫入任何內容(即使是 root)。 postgres 容器中的資料庫磁碟區似乎運作正常,所以我認為在兩個容器之間共用磁碟區時會出現問題。
任何想法?