When I try to run daphne in docker I have this problem. I have no idea to fix it :)
I use docker compose to build it. my project -nginx -redis -daphne -django channels
~/pyprj/Django# docker logs 3517329befc9
New pypi version: 0.2.0.2 (current: 0.1.8.7) | pip install -U g4f
Traceback (most recent call last):
File "/usr/local/bin/daphne", line 8, in <module>
sys.exit(CommandLineInterface.entrypoint())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/daphne/cli.py", line 171, in entrypoint
cls().run(sys.argv[1:])
File "/usr/local/lib/python3.12/site-packages/daphne/cli.py", line 233, in run
application = import_by_path(args.application)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/daphne/utils.py", line 12, in import_by_path
target = importlib.import_module(module_path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/importlib/__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 994, in exec_module
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "/Django/gptweb/gptweb/asgi.py", line 16, in <module>
django_asgi_app = get_asgi_application()
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/core/asgi.py", line 12, in get_asgi_application
django.setup(set_prefix=False)
File "/usr/local/lib/python3.12/site-packages/django/__init__.py", line 19, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/conf/__init__.py", line 89, in __getattr__
self._setup(name)
File "/usr/local/lib/python3.12/site-packages/django/conf/__init__.py", line 76, in _setup
self._wrapped = Settings(settings_module)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/django/conf/__init__.py", line 190, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/importlib/__init__.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1310, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
File "<frozen importlib._bootstrap>", line 1324, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'yourproject'
this is my docker-compose.yml file
services:
redis:
image: redis
restart: always
ports:
- 6379:6379
volumes:
- /gptweb/redis/data:/data
django:
build: ./gptweb
command: sh -c "gunicorn --env DJANGO_SETTINGS_MODULE=gptweb.settings gptweb.wsgi --bind 0.0.0.0:8001"
volumes:
- ./gptweb:/gptweb
- static_data:/gptweb/chat/static
ports:
- 8001:8001
- 8002:8002
depends_on:
- redis
env_file:
- ./env.dev
nginx:
build: ./nginx/
depends_on:
- django
ports:
- 80:80
volumes:
- static_data:/var/www/html/static
daphne:
build:
context: ./gptweb
dockerfile: Dockerfile.daphne
command: 'sh -c "daphne -b 0.0.0.0 -p 8002 gptweb.asgi:application"'
restart: always
volumes:
static_data:
This is my daphne docker file Dockerfile.daphne
WORKDIR /Django/gptweb
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONBUFFERED=1
RUN pip install --upgrade pip
COPY ./requirements.txt .
RUN pip install -r requirements.txt
COPY . .
I tried run daphne in guinicorn container but it does not work. Also I did this without supervisor
SOLVED I just changed the os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'yourproject.settings') to os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'gptweb.settings') And it's now working. I run daphne separatly from guinicorn image
I just changed the os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'yourproject.settings') to os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'gptweb.settings') And it's now working. I run daphne separatly from guinicorn image