1๐
I think the reason is because your containers are unable to talk to each other. By default all the containers are in bridge network and this issue arises. You can try grouping all the containers in a network as shown below.
version: '3.8'
services:
django_gunicorn:
volumes:
- static:/app/static
- media:/media
env_file:
- env
build:
context: .
ports:
- "8000:8000"
networks:
- dev_network
nginx:
build: ./nginx
volumes:
- static:/static
- media:/media
ports:
- "80:80"
depends_on:
- django_gunicorn
networks:
- dev_network
rabbitmq3:
image: rabbitmq:3-alpine
ports:
- 5672:5672
networks:
- dev_network
celery:
restart: always
build:
context: .
command: celery -A main worker -l info
env_file:
- env
depends_on:
- rabbitmq3
- django_gunicorn
networks:
- dev_network
networks:
dev_network:
external: false
volumes:
static:
media:
And in your celery configuration for broker URL, you need to specify it in this format.
amqp://username:password@rabbitmq3:5672/
in your entrypoint.sh add the below line at the end so that docker-compose commands also gets executed.
exec "$@"
or you can remove the Entrypoint from DockerFile and do as below.
for gunicorn
container command in docker-compose.yml
command:
[sh, -c, "python manage.py migrate && gunicorn main.wsgi:application --bind 0.0.0.0:8000 "]
Note : collect the static file before hand or you can append it in the above command
for celery
container command in docker-compose.yml remains same.
Note: using the second method is not an issue in this case. But if you have some complex validation or task to perform before container spin up, go with Entrypoint script only