得到一堆错误,最终导致



我创建了一个Django应用,尝试使用Gunicorn进行Docker。

我的Dockerfile和start.sh位于另一个名为approot的目录的根目录中。在approot中,您期望通过运行django-admin startproject看到的一切。我的wsgi.py文件位于app内名为approot的目录中。

这是我的...

requirements.txt:

Django>=1.8
gunicorn==19.6.0

Dockerfile:
#Dockerfile

# FROM directive instructing base image to build upon
FROM python:2-onbuild

# COPY startup script into known file location in container
COPY start.sh /start.sh

# EXPOSE port 8000 to allow communication to/from server
EXPOSE 8000

# CMD specifies the command to execute to start the server running
CMD ["/start.sh"]

start.sh:
#!/bin/bash

echo Starting Gunicorn.
cd approot
exec gunicorn app.wsgi:application \
    --bind 0.0.0.0:8000 \
    --workers 3

我的settings.py包括:
INSTALLED_APPS = [
     ...,
     'webpack_loader'
]

WSGI_APPLICATION = 'app.wsgi.application'

WEBPACK_LOADER = {
    'DEFAULT': {
        'CACHE': not DEBUG,
        'BUNDLE_DIR_NAME': 'bundles/',
        'STATS_FILE': join(PROJECT_ROOT, 'webpack-stats.json'),
        'POLL_INTERVAL': 0.1,
        'TIMEOUT': None,
    }
}

错误堆栈是
$ docker run -it -p 8000:8000 app
Starting Gunicorn.
[2017-10-31 02:23:31 +0000] [1] [INFO] Starting gunicorn 19.6.0
[2017-10-31 02:23:31 +0000] [1] [INFO] Listening at: http://0.0.0.0:8000 (1)
[2017-10-31 02:23:31 +0000] [1] [INFO] Using worker: sync
[2017-10-31 02:23:31 +0000] [8] [INFO] Booting worker with pid: 8
[2017-10-31 02:23:31 +0000] [9] [INFO] Booting worker with pid: 9
[2017-10-31 02:23:31 +0000] [12] [INFO] Booting worker with pid: 12
[2017-10-31 02:23:31 +0000] [8] [ERROR] Exception in worker process
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 557, in spawn_worker
worker.init_process()
  File "/usr/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 126, in init_process
self.load_wsgi()
  File "/usr/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 136, in load_wsgi
self.wsgi = self.app.wsgi()
  File "/usr/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
  File "/usr/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
return self.load_wsgiapp()
  File "/usr/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
return util.import_app(self.app_uri)
  File "/usr/local/lib/python2.7/site-packages/gunicorn/util.py", line 357, in import_app
__import__(module)
  File "/usr/src/app/approot/app/wsgi.py", line 16, in <module>
application = get_wsgi_application()
  File "/usr/local/lib/python2.7/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
django.setup(set_prefix=False)
  File "/usr/local/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
  File "/usr/local/lib/python2.7/site-packages/django/apps/config.py", line 94, in create
module = import_module(entry)
  File "/usr/local/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named webpack_loader
[2017-10-31 02:23:31 +0000] [8] [INFO] Worker exiting (pid: 8)
[2017-10-31 02:23:31 +0000] [9] [ERROR] Exception in worker process
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 557, in spawn_worker
worker.init_process()
  File "/usr/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 126, in init_process
self.load_wsgi()
  File "/usr/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 136, in load_wsgi
self.wsgi = self.app.wsgi()
  File "/usr/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
  File "/usr/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
return self.load_wsgiapp()
  File "/usr/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
return util.import_app(self.app_uri)
  File "/usr/local/lib/python2.7/site-packages/gunicorn/util.py", line 357, in import_app
__import__(module)
  File "/usr/src/app/approot/app/wsgi.py", line 16, in <module>
application = get_wsgi_application()
  File "/usr/local/lib/python2.7/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
django.setup(set_prefix=False)
  File "/usr/local/lib/python2.7/site-packages/django/__init__.py", line 27, in setup
apps.populate(settings.INSTALLED_APPS)
  File "/usr/local/lib/python2.7/site-packages/django/apps/registry.py", line 85, in populate
app_config = AppConfig.create(entry)
  File "/usr/local/lib/python2.7/site-packages/django/apps/config.py", line 94, in create
module = import_module(entry)
  File "/usr/local/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named webpack_loader
[2017-10-31 02:23:31 +0000] [9] [INFO] Worker exiting (pid: 9)
Traceback (most recent call last):
  File "/usr/local/bin/gunicorn", line 11, in <module>
sys.exit(run())
  File "/usr/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
  File "/usr/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 192, in run
super(Application, self).run()
  File "/usr/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 72, in run
Arbiter(self).run()
  File "/usr/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 218, in run
self.halt(reason=inst.reason, exit_status=inst.exit_status)
  File "/usr/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 331, in halt
self.stop()
  File "/usr/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 381, in stop
time.sleep(0.1)
  File "/usr/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 231, in handle_chld
self.reap_workers()
  File "/usr/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 506, in reap_workers
raise HaltServer(reason, self.WORKER_BOOT_ERROR)
gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>

最佳答案

我认为您在requirements.txt中缺少django-webpack-loader

关于django - 使用Webpack_Loader错误将Django Dockering,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47027119/

10-16 23:52