I have a dockerized Django project and everything works fine because Celery keeps displaying runserver logs instead of celery logs.
Here's my docker-compose.yml:
version: "3.8"
services:
api:
container_name: api
restart: always
build: .
networks:
- API_NETWORK
depends_on:
- redis
- database
ports:
- "8000:8000"
env_file:
- ./.env
command: bash -c /entrypoint.sh
database:
container_name: postgres
restart: always
image: postgres:latest
networks:
- API_NETWORK
volumes:
- pgdata:/var/lib/postgresql/data/
environment:
- POSTGRES_HOST_AUTH_METHOD=trust
redis:
container_name: redis
image: redis:latest
networks:
- API_NETWORK
celery:
container_name: celery
restart: always
build: .
networks:
- API_NETWORK
depends_on:
- api
- redis
- database
env_file:
- ./.env
command: celery -A dir_name worker -l debug
celery-beat:
container_name: celery-beat
restart: always
build: .
networks:
- API_NETWORK
depends_on:
- api
- redis
- database
env_file:
- ./.env
command: celery -A dir_name beat -l debug --scheduler django_celery_beat.schedulers:DatabaseScheduler
volumes:
pgdata:
networks:
API_NETWORK:
name: API_NETWORK
driver: bridge
...and here's my Dockerfile:
FROM python:3.9-slim-buster
ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential git gcc python3-dev \
&& python -m pip install --upgrade pip
RUN mkdir /dir_name
WORKDIR /dir_name
COPY . /dir_name
RUN pip install -r ./requirements.txt
RUN chmod +x ./entrypoint.sh
ENTRYPOINT ["sh", "./entrypoint.sh"]
The issue is instead of getting proper Celery logs in the celery
container, I keep getting django's runserver
command logs:
celery | Running migrations:
celery | No migrations to apply.
celery | Watching for file changes with StatReloader
celery | Performing system checks...
celery |
celery | System check identified no issues (0 silenced).
celery | June 08, 2021 - 02:41:29
celery | Django version 3.1.7, using settings 'cnapi.settings'
celery | Starting development server at http://0.0.0.0:8000/
celery | Quit the server with CONTROL-C.
If I open a shell in the container the run the celery command, it works fine. But why isn't it working from scratch? What am I doing wrong?
Remove the ENTRYPOINT ["sh", "./entrypoint.sh"]
from your Dockerfile and rebuild your images again.
I hope that will do the job.