Gunicorn'工作人员无法启动'运行Dockerized Django应用程序时

时间:2017-11-27 06:24:24

标签: python django docker gunicorn worker

我有一个分布式Dockerized应用程序,有四个服务:Django,Postgres,Caddy。这三个都是私有托管在Docker Hub上的。我试图让他们通过Docker Cloud与DigitalOcean节点一起运行。问题出在Django服务上,该服务与Gunicorn一起运行。

当我尝试启动该服务时,出现以下错误:

[django-1]2017-11-27T05:58:33.944903048Z Postgres is unavailable - sleeping
[django-1]2017-11-27T05:58:35.176033131Z Postgres is up - continuing...
[django-1]2017-11-27T05:58:36.023305930Z DEBUG 2017-11-27 00:58:36,023 base 8 140468605011712 Configuring Raven for host: <raven.conf.remote.RemoteConfig object at 0x7fc15b2b59b0>
[django-1]2017-11-27T05:58:37.755913984Z 0 static files copied.
[django-1]2017-11-27T05:58:38.117470416Z [2017-11-27 05:58:38 +0000] [12] [INFO] Starting gunicorn 19.7.1
[django-1]2017-11-27T05:58:38.118213362Z [2017-11-27 05:58:38 +0000] [12] [INFO] Listening at: http://0.0.0.0:5000 (12)
[django-1]2017-11-27T05:58:38.118423391Z [2017-11-27 05:58:38 +0000] [12] [INFO] Using worker: sync
[django-1]2017-11-27T05:58:38.122410705Z [2017-11-27 05:58:38 +0000] [15] [INFO] Booting worker with pid: 15
[django-1]2017-11-27T05:58:38.127667063Z [2017-11-27 05:58:38 +0000] [16] [INFO] Booting worker with pid: 16
[django-1]2017-11-27T05:58:38.131574049Z [2017-11-27 05:58:38 +0000] [17] [INFO] Booting worker with pid: 17
[django-1]2017-11-27T05:58:38.219843431Z [2017-11-27 05:58:38 +0000] [18] [INFO] Booting worker with pid: 18
[django-1]2017-11-27T05:58:38.702716621Z [2017-11-27 05:58:38 +0000] [23] [INFO] Booting worker with pid: 23
[django-1]2017-11-27T05:58:38.876025732Z [2017-11-27 05:58:38 +0000] [24] [INFO] Booting worker with pid: 24
[django-1]2017-11-27T05:58:39.063798754Z [2017-11-27 05:58:39 +0000] [26] [INFO] Booting worker with pid: 26
[django-1]2017-11-27T05:58:39.312288894Z [2017-11-27 05:58:39 +0000] [28] [INFO] Booting worker with pid: 28
[django-1]2017-11-27T05:58:39.597721523Z [2017-11-27 05:58:39 +0000] [30] [INFO] Booting worker with pid: 30
[django-1]2017-11-27T05:58:39.873687316Z [2017-11-27 05:58:39 +0000] [26] [ERROR] Exception in worker process
[django-1]2017-11-27T05:58:39.873719606Z Traceback (most recent call last):
[django-1]2017-11-27T05:58:39.873724356Z   File "/usr/local/lib/python3.5/site-packages/gunicorn/arbiter.py", line 578, in spawn_worker
[django-1]2017-11-27T05:58:39.873727998Z     worker.init_process()
[django-1]2017-11-27T05:58:39.873731641Z   File "/usr/local/lib/python3.5/site-packages/gunicorn/workers/base.py", line 126, in init_process
[django-1]2017-11-27T05:58:39.873735043Z     self.load_wsgi()
[django-1]2017-11-27T05:58:39.873738083Z   File "/usr/local/lib/python3.5/site-packages/gunicorn/workers/base.py", line 135, in load_wsgi
[django-1]2017-11-27T05:58:39.873741369Z     self.wsgi = self.app.wsgi()
[django-1]2017-11-27T05:58:39.873744486Z   File "/usr/local/lib/python3.5/site-packages/gunicorn/app/base.py", line 67, in wsgi
[django-1]2017-11-27T05:58:39.873747924Z     self.callable = self.load()
[django-1]2017-11-27T05:58:39.873750708Z   File "/usr/local/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
[django-1]2017-11-27T05:58:39.873753810Z     return self.load_wsgiapp()
[django-1]2017-11-27T05:58:39.873756734Z   File "/usr/local/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
[django-1]2017-11-27T05:58:39.873759813Z     return util.import_app(self.app_uri)
[django-1]2017-11-27T05:58:39.873762795Z   File "/usr/local/lib/python3.5/site-packages/gunicorn/util.py", line 352, in import_app
[django-1]2017-11-27T05:58:39.873773249Z     __import__(module)
[django-1]2017-11-27T05:58:39.873776283Z   File "/app/config/wsgi.py", line 27, in <module>
[django-1]2017-11-27T05:58:39.873779698Z     from raven.contrib.django.raven_compat.middleware.wsgi import Sentry
[django-1]2017-11-27T05:58:39.873782548Z   File "/usr/local/lib/python3.5/site-packages/raven/__init__.py", line 54, in <module>
[django-1]2017-11-27T05:58:39.873785561Z     from raven.base import *  # NOQA
[django-1]2017-11-27T05:58:39.873788158Z   File "/usr/local/lib/python3.5/site-packages/raven/base.py", line 37, in <module>
[django-1]2017-11-27T05:58:39.873791123Z     from raven.conf.remote import RemoteConfig
[django-1]2017-11-27T05:58:39.873793778Z   File "/usr/local/lib/python3.5/site-packages/raven/conf/remote.py", line 36, in <module>
[django-1]2017-11-27T05:58:39.873796967Z     DEFAULT_TRANSPORT = discover_default_transport()
[django-1]2017-11-27T05:58:39.873802155Z   File "/usr/local/lib/python3.5/site-packages/raven/conf/remote.py", line 18, in discover_default_transport
[django-1]2017-11-27T05:58:39.873805147Z     from raven.transport.threaded import ThreadedHTTPTransport
[django-1]2017-11-27T05:58:39.873807996Z   File "/usr/local/lib/python3.5/site-packages/raven/transport/__init__.py", line 14, in <module>
[django-1]2017-11-27T05:58:39.873811081Z     from raven.transport.exceptions import *  # NOQA
[django-1]2017-11-27T05:58:39.873813995Z   File "<frozen importlib._bootstrap>", line 968, in _find_and_load
[django-1]2017-11-27T05:58:39.873817250Z   File "<frozen importlib._bootstrap>", line 957, in _find_and_load_unlocked
[django-1]2017-11-27T05:58:39.873820449Z   File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
[django-1]2017-11-27T05:58:39.873823735Z   File "<frozen importlib._bootstrap_external>", line 693, in exec_module
[django-1]2017-11-27T05:58:39.873826698Z   File "<frozen importlib._bootstrap_external>", line 798, in get_code
[django-1]2017-11-27T05:58:39.873829538Z   File "<frozen importlib._bootstrap_external>", line 851, in get_data
[django-1]2017-11-27T05:58:39.874208481Z OSError: [Errno 12] Cannot allocate memory
[django-1]2017-11-27T05:58:39.874928629Z [2017-11-27 05:58:39 +0000] [26] [INFO] Worker exiting (pid: 26)
[django-1]2017-11-27T05:58:39.879239068Z [2017-11-27 05:58:39 +0000] [32] [INFO] Booting worker with pid: 32
[django-1]2017-11-27T05:58:39.886388144Z [2017-11-27 05:58:39 +0000] [28] [ERROR] Exception in worker process
[django-1]2017-11-27T05:58:39.886403449Z Traceback (most recent call last):
[django-1]2017-11-27T05:58:39.886407503Z   File "/usr/local/lib/python3.5/site-packages/gunicorn/arbiter.py", line 578, in spawn_worker
[django-1]2017-11-27T05:58:39.886410903Z     worker.init_process()
[django-1]2017-11-27T05:58:39.886414519Z   File "/usr/local/lib/python3.5/site-packages/gunicorn/workers/base.py", line 126, in init_process
[django-1]2017-11-27T05:58:39.886417653Z     self.load_wsgi()
[django-1]2017-11-27T05:58:39.886420456Z   File "/usr/local/lib/python3.5/site-packages/gunicorn/workers/base.py", line 135, in load_wsgi
[django-1]2017-11-27T05:58:39.886439612Z     self.wsgi = self.app.wsgi()
[django-1]2017-11-27T05:58:39.886443180Z   File "/usr/local/lib/python3.5/site-packages/gunicorn/app/base.py", line 67, in wsgi
[django-1]2017-11-27T05:58:39.886446306Z     self.callable = self.load()
[django-1]2017-11-27T05:58:39.886449173Z   File "/usr/local/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
[django-1]2017-11-27T05:58:39.886459776Z     return self.load_wsgiapp()
[django-1]2017-11-27T05:58:39.886462879Z   File "/usr/local/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
[django-1]2017-11-27T05:58:39.886465861Z     return util.import_app(self.app_uri)
[django-1]2017-11-27T05:58:39.886468629Z   File "/usr/local/lib/python3.5/site-packages/gunicorn/util.py", line 352, in import_app
[django-1]2017-11-27T05:58:39.886471615Z     __import__(module)
[django-1]2017-11-27T05:58:39.886474466Z   File "/app/config/wsgi.py", line 19, in <module>
[django-1]2017-11-27T05:58:39.886477936Z     from django.core.wsgi import get_wsgi_application
[django-1]2017-11-27T05:58:39.886480709Z   File "/usr/local/lib/python3.5/site-packages/django/core/wsgi.py", line 2, in <module>
[django-1]2017-11-27T05:58:39.886483823Z     from django.core.handlers.wsgi import WSGIHandler
[django-1]2017-11-27T05:58:39.886486722Z   File "/usr/local/lib/python3.5/site-packages/django/core/handlers/wsgi.py", line 10, in <module>
[django-1]2017-11-27T05:58:39.886489819Z     from django import http
[django-1]2017-11-27T05:58:39.886492510Z   File "/usr/local/lib/python3.5/site-packages/django/http/__init__.py", line 5, in <module>
[django-1]2017-11-27T05:58:39.886495549Z     from django.http.response import (
[django-1]2017-11-27T05:58:39.886498229Z   File "/usr/local/lib/python3.5/site-packages/django/http/response.py", line 13, in <module>
[django-1]2017-11-27T05:58:39.886501295Z     from django.core.serializers.json import DjangoJSONEncoder
[django-1]2017-11-27T05:58:39.886503980Z   File "/usr/local/lib/python3.5/site-packages/django/core/serializers/__init__.py", line 23, in <module>
[django-1]2017-11-27T05:58:39.886507045Z     from django.core.serializers.base import SerializerDoesNotExist
[django-1]2017-11-27T05:58:39.886510779Z   File "/usr/local/lib/python3.5/site-packages/django/core/serializers/base.py", line 4, in <module>
[django-1]2017-11-27T05:58:39.886513962Z     from django.db import models
[django-1]2017-11-27T05:58:39.886516647Z   File "/usr/local/lib/python3.5/site-packages/django/db/models/__init__.py", line 5, in <module>
[django-1]2017-11-27T05:58:39.886519655Z     from django.db.models.aggregates import *  # NOQA
[django-1]2017-11-27T05:58:39.886522493Z   File "/usr/local/lib/python3.5/site-packages/django/db/models/aggregates.py", line 5, in <module>
[django-1]2017-11-27T05:58:39.886525550Z     from django.db.models.expressions import Func, Star
[django-1]2017-11-27T05:58:39.886528341Z   File "/usr/local/lib/python3.5/site-packages/django/db/models/expressions.py", line 6, in <module>
[django-1]2017-11-27T05:58:39.886531259Z     from django.db.models import fields
[django-1]2017-11-27T05:58:39.886537331Z   File "/usr/local/lib/python3.5/site-packages/django/db/models/fields/__init__.py", line 17, in <module>
[django-1]2017-11-27T05:58:39.886540471Z     from django.core import checks, exceptions, validators
[django-1]2017-11-27T05:58:39.886543207Z   File "/usr/local/lib/python3.5/site-packages/django/core/checks/__init__.py", line 11, in <module>
[django-1]2017-11-27T05:58:39.886546124Z     import django.core.checks.caches  # NOQA isort:skip
[django-1]2017-11-27T05:58:39.886548847Z   File "/usr/local/lib/python3.5/site-packages/django/core/checks/caches.py", line 4, in <module>
[django-1]2017-11-27T05:58:39.886551879Z     from django.core.cache import DEFAULT_CACHE_ALIAS
[django-1]2017-11-27T05:58:39.886554690Z   File "/usr/local/lib/python3.5/site-packages/django/core/cache/__init__.py", line 19, in <module>
[django-1]2017-11-27T05:58:39.886557807Z     from django.core.cache.backends.base import (
[django-1]2017-11-27T05:58:39.886560911Z   File "<frozen importlib._bootstrap>", line 968, in _find_and_load
[django-1]2017-11-27T05:58:39.886563930Z   File "<frozen importlib._bootstrap>", line 957, in _find_and_load_unlocked
[django-1]2017-11-27T05:58:39.886566890Z   File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
[django-1]2017-11-27T05:58:39.886569847Z   File "<frozen importlib._bootstrap_external>", line 693, in exec_module
[django-1]2017-11-27T05:58:39.886572800Z   File "<frozen importlib._bootstrap_external>", line 798, in get_code
[django-1]2017-11-27T05:58:39.886575696Z   File "<frozen importlib._bootstrap_external>", line 851, in get_data
[django-1]2017-11-27T05:58:39.886626190Z OSError: [Errno 12] Cannot allocate memory
[django-1]2017-11-27T05:58:39.887806259Z [2017-11-27 05:58:39 +0000] [28] [INFO] Worker exiting (pid: 28)
[django-1]2017-11-27T05:58:40.107783939Z [2017-11-27 05:58:40 +0000] [34] [INFO] Booting worker with pid: 34
[django-1]2017-11-27T05:58:40.636177343Z [2017-11-27 05:58:40 +0000] [32] [ERROR] Exception in worker process
[django-1]2017-11-27T05:58:40.636196484Z Traceback (most recent call last):
[django-1]2017-11-27T05:58:40.636200586Z   File "/usr/local/lib/python3.5/site-packages/gunicorn/arbiter.py", line 578, in spawn_worker
[django-1]2017-11-27T05:58:40.636204011Z     worker.init_process()
[django-1]2017-11-27T05:58:40.636207366Z   File "/usr/local/lib/python3.5/site-packages/gunicorn/workers/base.py", line 126, in init_process
[django-1]2017-11-27T05:58:40.636210542Z     self.load_wsgi()
[django-1]2017-11-27T05:58:40.636213366Z   File "/usr/local/lib/python3.5/site-packages/gunicorn/workers/base.py", line 135, in load_wsgi
[django-1]2017-11-27T05:58:40.636224731Z     self.wsgi = self.app.wsgi()
[django-1]2017-11-27T05:58:40.636227809Z   File "/usr/local/lib/python3.5/site-packages/gunicorn/app/base.py", line 67, in wsgi
[django-1]2017-11-27T05:58:40.636230950Z     self.callable = self.load()
[django-1]2017-11-27T05:58:40.636233967Z   File "/usr/local/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
[django-1]2017-11-27T05:58:40.636237087Z     return self.load_wsgiapp()
[django-1]2017-11-27T05:58:40.636246910Z   File "/usr/local/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
[django-1]2017-11-27T05:58:40.636250135Z     return util.import_app(self.app_uri)
[django-1]2017-11-27T05:58:40.636253001Z   File "/usr/local/lib/python3.5/site-packages/gunicorn/util.py", line 352, in import_app
[django-1]2017-11-27T05:58:40.636255906Z     __import__(module)
[django-1]2017-11-27T05:58:40.636258668Z   File "/app/config/wsgi.py", line 27, in <module>
[django-1]2017-11-27T05:58:40.636262110Z     from raven.contrib.django.raven_compat.middleware.wsgi import Sentry
[django-1]2017-11-27T05:58:40.636264932Z   File "/usr/local/lib/python3.5/site-packages/raven/__init__.py", line 54, in <module>
[django-1]2017-11-27T05:58:40.636268028Z     from raven.base import *  # NOQA
[django-1]2017-11-27T05:58:40.636270728Z   File "/usr/local/lib/python3.5/site-packages/raven/base.py", line 37, in <module>
[django-1]2017-11-27T05:58:40.636273641Z     from raven.conf.remote import RemoteConfig
[django-1]2017-11-27T05:58:40.636276241Z   File "/usr/local/lib/python3.5/site-packages/raven/conf/remote.py", line 36, in <module>
[django-1]2017-11-27T05:58:40.636279228Z     DEFAULT_TRANSPORT = discover_default_transport()
[django-1]2017-11-27T05:58:40.636281868Z   File "/usr/local/lib/python3.5/site-packages/raven/conf/remote.py", line 18, in discover_default_transport
[django-1]2017-11-27T05:58:40.636284760Z     from raven.transport.threaded import ThreadedHTTPTransport
[django-1]2017-11-27T05:58:40.636287497Z   File "/usr/local/lib/python3.5/site-packages/raven/transport/__init__.py", line 17, in <module>
[django-1]2017-11-27T05:58:40.636290459Z     from raven.transport.requests import *  # NOQA
[django-1]2017-11-27T05:58:40.636293099Z   File "/usr/local/lib/python3.5/site-packages/raven/transport/requests.py", line 13, in <module>
[django-1]2017-11-27T05:58:40.636296070Z     import requests
[django-1]2017-11-27T05:58:40.636298666Z   File "/usr/local/lib/python3.5/site-packages/requests/__init__.py", line 44, in <module>
[django-1]2017-11-27T05:58:40.636301641Z     import chardet
[django-1]2017-11-27T05:58:40.636304191Z   File "/usr/local/lib/python3.5/site-packages/chardet/__init__.py", line 20, in <module>
[django-1]2017-11-27T05:58:40.636320047Z     from .universaldetector import UniversalDetector
[django-1]2017-11-27T05:58:40.636322880Z   File "/usr/local/lib/python3.5/site-packages/chardet/universaldetector.py", line 47, in <module>
[django-1]2017-11-27T05:58:40.636325953Z     from .mbcsgroupprober import MBCSGroupProber
[django-1]2017-11-27T05:58:40.636328617Z   File "/usr/local/lib/python3.5/site-packages/chardet/mbcsgroupprober.py", line 32, in <module>
[django-1]2017-11-27T05:58:40.636331644Z     from .sjisprober import SJISProber
[django-1]2017-11-27T05:58:40.636334446Z   File "/usr/local/lib/python3.5/site-packages/chardet/sjisprober.py", line 30, in <module>
[django-1]2017-11-27T05:58:40.636337417Z     from .chardistribution import SJISDistributionAnalysis
[django-1]2017-11-27T05:58:40.636340193Z   File "/usr/local/lib/python3.5/site-packages/chardet/chardistribution.py", line 32, in <module>
[django-1]2017-11-27T05:58:40.636346588Z     from .gb2312freq import (GB2312_CHAR_TO_FREQ_ORDER, GB2312_TABLE_SIZE,
[django-1]2017-11-27T05:58:40.636349550Z   File "<frozen importlib._bootstrap>", line 968, in _find_and_load
[django-1]2017-11-27T05:58:40.636352745Z   File "<frozen importlib._bootstrap>", line 957, in _find_and_load_unlocked
[django-1]2017-11-27T05:58:40.636355841Z   File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
[django-1]2017-11-27T05:58:40.636358820Z   File "<frozen importlib._bootstrap_external>", line 693, in exec_module
[django-1]2017-11-27T05:58:40.636361969Z   File "<frozen importlib._bootstrap_external>", line 798, in get_code
[django-1]2017-11-27T05:58:40.636364791Z   File "<frozen importlib._bootstrap_external>", line 851, in get_data
[django-1]2017-11-27T05:58:40.636420625Z OSError: [Errno 12] Cannot allocate memory
[django-1]2017-11-27T05:58:40.636930892Z [2017-11-27 05:58:40 +0000] [32] [INFO] Worker exiting (pid: 32)
[django-1]2017-11-27T05:58:40.748217102Z Traceback (most recent call last):
[django-1]2017-11-27T05:58:40.748320932Z   File "/usr/local/lib/python3.5/site-packages/gunicorn/arbiter.py", line 209, in run
[django-1]2017-11-27T05:58:40.748734032Z     self.sleep()
[django-1]2017-11-27T05:58:40.748782547Z   File "/usr/local/lib/python3.5/site-packages/gunicorn/arbiter.py", line 359, in sleep
[django-1]2017-11-27T05:58:40.749078539Z     ready = select.select([self.PIPE[0]], [], [], 1.0)
[django-1]2017-11-27T05:58:40.749114363Z   File "/usr/local/lib/python3.5/site-packages/gunicorn/arbiter.py", line 244, in handle_chld
[django-1]2017-11-27T05:58:40.749367274Z     self.reap_workers()
[django-1]2017-11-27T05:58:40.749418962Z   File "/usr/local/lib/python3.5/site-packages/gunicorn/arbiter.py", line 524, in reap_workers
[django-1]2017-11-27T05:58:40.749769021Z     raise HaltServer(reason, self.WORKER_BOOT_ERROR)
[django-1]2017-11-27T05:58:40.749826025Z gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
[django-1]2017-11-27T05:58:40.749867861Z 
[django-1]2017-11-27T05:58:40.749873734Z During handling of the above exception, another exception occurred:
[django-1]2017-11-27T05:58:40.749876916Z 
[django-1]2017-11-27T05:58:40.749897120Z Traceback (most recent call last):
[django-1]2017-11-27T05:58:40.749949856Z   File "/usr/local/bin/gunicorn", line 11, in <module>
[django-1]2017-11-27T05:58:40.750334960Z     sys.exit(run())
[django-1]2017-11-27T05:58:40.750373492Z   File "/usr/local/lib/python3.5/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
[django-1]2017-11-27T05:58:40.750607890Z     WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
[django-1]2017-11-27T05:58:40.750643199Z   File "/usr/local/lib/python3.5/site-packages/gunicorn/app/base.py", line 203, in run
[django-1]2017-11-27T05:58:40.750914893Z     super(Application, self).run()
[django-1]2017-11-27T05:58:40.750948941Z   File "/usr/local/lib/python3.5/site-packages/gunicorn/app/base.py", line 72, in run
[django-1]2017-11-27T05:58:40.751160921Z     Arbiter(self).run()
[django-1]2017-11-27T05:58:40.751205745Z   File "/usr/local/lib/python3.5/site-packages/gunicorn/arbiter.py", line 231, in run
[django-1]2017-11-27T05:58:40.751499892Z     self.halt(reason=inst.reason, exit_status=inst.exit_status)
[django-1]2017-11-27T05:58:40.751535848Z   File "/usr/local/lib/python3.5/site-packages/gunicorn/arbiter.py", line 344, in halt
[django-1]2017-11-27T05:58:40.751832653Z     self.stop()
[django-1]2017-11-27T05:58:40.751867719Z   File "/usr/local/lib/python3.5/site-packages/gunicorn/arbiter.py", line 393, in stop
[django-1]2017-11-27T05:58:40.752170458Z     time.sleep(0.1)
[django-1]2017-11-27T05:58:40.752204754Z   File "/usr/local/lib/python3.5/site-packages/gunicorn/arbiter.py", line 244, in handle_chld
[django-1]2017-11-27T05:58:40.752458600Z     self.reap_workers()
[django-1]2017-11-27T05:58:40.752493278Z   File "/usr/local/lib/python3.5/site-packages/gunicorn/arbiter.py", line 524, in reap_workers
[django-1]2017-11-27T05:58:40.752858150Z     raise HaltServer(reason, self.WORKER_BOOT_ERROR)
[django-1]2017-11-27T05:58:40.752909364Z gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>

我不确定问题究竟是什么。 Gunicorn在gunicorn.sh开始,看起来像这样:

#!/usr/bin/env bash

set -o errexit
set -o pipefail
set -o nounset


python /app/manage.py collectstatic --noinput
/usr/local/bin/gunicorn config.wsgi -w 4 -b 0.0.0.0:5000 --chdir=/app

当我在本地构建和运行我的容器时,我没有收到上述错误。

Django容器的我的Dockerfile如下所示:

FROM python:3.5

ENV PYTHONUNBUFFERED 1

RUN groupadd -r django \
    && useradd -r -g django django

# Requirements have to be pulled and installed here, otherwise caching won't work
COPY ./requirements /requirements
RUN pip install --no-cache-dir -r /requirements/production.txt \
    && rm -rf /requirements

COPY ./compose/production/django/gunicorn.sh /gunicorn.sh
RUN sed -i 's/\r//' /gunicorn.sh
RUN chmod +x /gunicorn.sh
RUN chown django /gunicorn.sh

COPY ./compose/production/django/entrypoint.sh /entrypoint.sh
RUN sed -i 's/\r//' /entrypoint.sh
RUN chmod +x /entrypoint.sh
RUN chown django /entrypoint.sh

COPY ./compose/production/django/celery/worker/start.sh /start-celeryworker.sh
RUN sed -i 's/\r//' /start-celeryworker.sh
RUN chmod +x /start-celeryworker.sh

COPY ./compose/production/django/celery/beat/start.sh /start-celerybeat.sh
RUN sed -i 's/\r//' /start-celerybeat.sh
RUN chmod +x /start-celerybeat.sh

COPY . /app

RUN chown -R django /app

USER django

WORKDIR /app

ENTRYPOINT ["/entrypoint.sh"]

我的Docker Compose文件的相关部分(在Docker Cloud Django服务设置中复制)如下所示:

services:
  django:
    build:
      context: .
      dockerfile: ./compose/production/django/Dockerfile
    depends_on:
      - postgres
      - redis
    env_file: .env
    command: /gunicorn.sh

任何人都可以帮我指出正确的方向吗?谢谢!

0 个答案:

没有答案