I'm trying to setup my django project with docker. It will have multiple containers one is for code that is server, worker for celery, redis for redis, db for postgres and there is nginx. Every one of them are running without any error but the localhost:8080 is not accessible. I tried accessing localhost:8000 directly and it is still not accessible. Here's all the relevant configuration files of docker.the docker-compose.yml is as:
version: '2'services: nginx: restart: always image: nginx:1.23-alpine ports: - 8080:8080 volumes: - /default.conf:/etc/nginx/conf.d - static_volume:/app/django_static server: restart: unless-stopped build: context: . dockerfile: Dockerfile entrypoint: /app/server-entrypoint.sh volumes: - static_volume:/app/django_static expose: - 8000 environment: DEBUG: "True" CELERY_BROKER_URL: "redis://redis:6379/0" CELERY_RESULT_BACKEND: "redis://redis:6379/0" DJANGO_DB: postgresql POSTGRES_HOST: db POSTGRES_NAME: postgres POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres POSTGRES_PORT: 5432 worker: restart: unless-stopped build: context: . dockerfile: Dockerfile entrypoint: /app/worker-entrypoint.sh volumes: - static_volume:/app/django_static environment: DEBUG: "True" CELERY_BROKER_URL: "redis://redis:6379/0" CELERY_RESULT_BACKEND: "redis://redis:6379/0" DJANGO_DB: postgresql POSTGRES_HOST: db POSTGRES_NAME: postgres POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres POSTGRES_PORT: 5432 depends_on: - server - redis redis: restart: unless-stopped image: redis:7.0.5-alpine expose: - 6379 db: image: postgres:13.0-alpine restart: unless-stopped volumes: - postgres_data:/var/lib/postgresql/data/ environment: POSTGRES_DB: postgres POSTGRES_USER: postgres POSTGRES_PASSWORD: postgres expose: - 5432volumes: static_volume: {} postgres_data: {}Dockerfile:
#!/bin/bash# Base imageFROM python:3.11.4# Set working directoryWORKDIR /appRUN pip install --upgrade pipRUN pip install gunicornADD ./requirements.txt /app/RUN pip install -r requirements.txtADD . /app/ ADD ./server-entrypoint.sh /app/ADD ./worker-entrypoint.sh /app/RUN chmod +x /app/server-entrypoint.shRUN chmod +x /app/worker-entrypoint.shserver-entrypoint.sh:
#!/bin/bash# Run database migrations or initialization tasksecho "Running database migrations..."python manage.py makemigrationspython manage.py migrate# Start the development serverecho "Starting Django application..."gunicorn core.wsgi --bind 0.0.0.0:8000 --workers 4 --threads 4worker-entrypoint.sh:
#!/bin/bashecho "Starting celery worker..."# Run a workercelery -A core worker --loglevel=info --concurrency 1 -Eand lastly the default.conf is as:
server { listen 80; server_name _; server_tokens off; client_max_body_size 20M; location / { try_files $uri @proxy_api; } location /admin { try_files $uri @proxy_api; } location @proxy_api { proxy_set_header Host $http_host; proxy_redirect off; proxy_pass http://server:8000; } location /django_static/ { autoindex on; alias /app/django_static/; }}this is the whole logs of the containers:
docker compose up [+] Running 5/5✔ Container celery-redis-django-nginx-1 Created 0.0s ✔ Container celery-redis-django-db-1 Created 0.0s ✔ Container celery-redis-django-redis-1 Created 0.0s ✔ Container celery-redis-django-server-1 Recreated 0.3s ✔ Container celery-redis-django-worker-1 Recreated 0.3s Attaching to db-1, nginx-1, redis-1, server-1, worker-1server-1 | exec /app/server-entrypoint.sh: no such file or directorynginx-1 | /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configurationnginx-1 | /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/nginx-1 | /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.shnginx-1 | 10-listen-on-ipv6-by-default.sh: info: /etc/nginx/conf.d/default.conf is not a file or does not existnginx-1 | /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.shredis-1 | 1:C 26 Jan 2024 09:28:48.558 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Ooredis-1 | 1:C 26 Jan 2024 09:28:48.559 # Redis version=7.0.5, bits=64, commit=00000000, modified=0, pid=1, just startedredis-1 | 1:C 26 Jan 2024 09:28:48.559 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.confredis-1 | 1:M 26 Jan 2024 09:28:48.559 * monotonic clock: POSIX clock_gettimeredis-1 | 1:M 26 Jan 2024 09:28:48.562 * Running mode=standalone, port=6379.redis-1 | 1:M 26 Jan 2024 09:28:48.562 # Server initializedredis-1 | 1:M 26 Jan 2024 09:28:48.562 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.redis-1 | 1:M 26 Jan 2024 09:28:48.562 * Ready to accept connectionsnginx-1 | /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.shnginx-1 | /docker-entrypoint.sh: Configuration complete; ready for start updb-1 | db-1 | PostgreSQL Database directory appears to contain a database; Skipping initializationdb-1 |nginx-1 | 2024/01/26 09:28:51 [notice] 1#1: using the "epoll" event methodnginx-1 | 2024/01/26 09:28:51 [notice] 1#1: nginx/1.23.4nginx-1 | 2024/01/26 09:28:51 [notice] 1#1: built by gcc 12.2.1 20220924 (Alpine 12.2.1_git20220924-r4)nginx-1 | 2024/01/26 09:28:51 [notice] 1#1: OS: Linux 5.15.133.1-microsoft-standard-WSL2nginx-1 | 2024/01/26 09:28:51 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576nginx-1 | 2024/01/26 09:28:51 [notice] 1#1: start worker processesnginx-1 | 2024/01/26 09:28:51 [notice] 1#1: start worker process 20nginx-1 | 2024/01/26 09:28:51 [notice] 1#1: start worker process 21nginx-1 | 2024/01/26 09:28:51 [notice] 1#1: start worker process 22nginx-1 | 2024/01/26 09:28:51 [notice] 1#1: start worker process 23nginx-1 | 2024/01/26 09:28:51 [notice] 1#1: start worker process 24nginx-1 | 2024/01/26 09:28:51 [notice] 1#1: start worker process 25nginx-1 | 2024/01/26 09:28:51 [notice] 1#1: start worker process 26nginx-1 | 2024/01/26 09:28:51 [notice] 1#1: start worker process 27db-1 | 2024-01-26 09:28:53.150 UTC [1] LOG: starting PostgreSQL 13.0 on x86_64-pc-linux-musl, compiled by gcc (Alpine 9.3.0) 9.3.0, 64-bitdb-1 | 2024-01-26 09:28:53.150 UTC [1] LOG: listening on IPv4 address "0.0.0.0", port 5432db-1 | 2024-01-26 09:28:53.150 UTC [1] LOG: listening on IPv6 address "::", port 5432db-1 | 2024-01-26 09:28:53.159 UTC [1] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"db-1 | 2024-01-26 09:28:53.170 UTC [22] LOG: database system was shut down at 2024-01-26 08:45:06 UTCdb-1 | 2024-01-26 09:28:53.180 UTC [1] LOG: database system is ready to accept connectionsworker-1 | Starting celery worker...server-1 exited with code 0worker-1 | /usr/local/lib/python3.11/site-packages/celery/platforms.py:829: SecurityWarning: You're running the worker with superuser privileges: this isworker-1 | absolutely not recommended!worker-1 |worker-1 | Please specify a different user using the --uid option.worker-1 |worker-1 | User information: uid=0 euid=0 gid=0 egid=0worker-1 |worker-1 | warnings.warn(SecurityWarning(ROOT_DISCOURAGED.format(worker-1 | worker-1 | -------------- celery@8d0c0884d6ae v5.3.6 (emerald-rush)worker-1 | --- ***** -----worker-1 | -- ******* ---- Linux-5.15.133.1-microsoft-standard-WSL2-x86_64-with-glibc2.36 2024-01-26 09:29:03worker-1 | - *** --- * ---worker-1 | - ** ---------- [config]worker-1 | - ** ---------- .> app: core:0x7f97b38c6890worker-1 | - ** ---------- .> transport: redis://redis:6379/0worker-1 | - ** ---------- .> results: redis://redis:6379/0worker-1 | - *** --- * --- .> concurrency: 1 (prefork)worker-1 | -- ******* ---- .> task events: ONworker-1 | --- ***** -----worker-1 | -------------- [queues]worker-1 | .> celery exchange=celery(direct) key=celeryworker-1 |worker-1 |worker-1 | [tasks]worker-1 | . core.celery.debug_taskworker-1 | . send_email_taskworker-1 |worker-1 | [2024-01-26 09:29:03,762: WARNING/MainProcess] /usr/local/lib/python3.11/site-packages/celery/worker/consumer/consumer.py:507: CPendingDeprecationWarning: The broker_connection_retry configuration setting will no longer determineworker-1 | whether broker connection retries are made during startup in Celery 6.0 and above.worker-1 | If you wish to retain the existing behavior for retrying connections on startup,worker-1 | you should set broker_connection_retry_on_startup to True.worker-1 | warnings.warn(worker-1 |worker-1 | [2024-01-26 09:29:03,873: INFO/MainProcess] Connected to redis://redis:6379/0worker-1 | [2024-01-26 09:29:03,874: WARNING/MainProcess] /usr/local/lib/python3.11/site-packages/celery/worker/consumer/consumer.py:507: CPendingDeprecationWarning: The broker_connection_retry configuration setting will no longer determineworker-1 | whether broker connection retries are made during startup in Celery 6.0 and above.worker-1 | If you wish to retain the existing behavior for retrying connections on startup,worker-1 | you should set broker_connection_retry_on_startup to True.worker-1 | warnings.warn(worker-1 |worker-1 | [2024-01-26 09:29:03,878: INFO/MainProcess] mingle: searching for neighborsworker-1 | [2024-01-26 09:29:04,887: INFO/MainProcess] mingle: all aloneworker-1 | [2024-01-26 09:29:04,901: INFO/MainProcess] celery@8d0c0884d6ae ready.server-1 | exec /app/server-entrypoint.sh: no such file or directoryserver-1 | exec /app/server-entrypoint.sh: no such file or directoryserver-1 | exec /app/server-entrypoint.sh: no such file or directoryserver-1 | exec /app/server-entrypoint.sh: no such file or directoryserver-1 | exec /app/server-entrypoint.sh: no such file or directoryserver-1 exited with code 1