芹菜显示 django 的运行服务器日志而不是芹菜日志
Celery showing django's runserver logs instead of celery logs
我有一个 docker 化的 Django 项目,一切正常,因为 Celery 一直显示 运行 服务器日志而不是 celery 日志。
这是我的 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
...这是我的 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"]
问题是我没有在 celery
容器中获取正确的 Celery 日志,而是不断获取 django 的 runserver
命令日志:
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.
如果我在容器中打开一个 shell 的 运行 芹菜命令,它工作正常。但为什么它不能从头开始工作呢?我做错了什么?
从您的 Dockerfile 中删除 ENTRYPOINT ["sh", "./entrypoint.sh"]
并再次重建您的映像。
我希望这能完成工作。
我有一个 docker 化的 Django 项目,一切正常,因为 Celery 一直显示 运行 服务器日志而不是 celery 日志。
这是我的 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
...这是我的 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"]
问题是我没有在 celery
容器中获取正确的 Celery 日志,而是不断获取 django 的 runserver
命令日志:
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.
如果我在容器中打开一个 shell 的 运行 芹菜命令,它工作正常。但为什么它不能从头开始工作呢?我做错了什么?
从您的 Dockerfile 中删除 ENTRYPOINT ["sh", "./entrypoint.sh"]
并再次重建您的映像。
我希望这能完成工作。