我有一个k8s集群,我在那里部署了我的django应用程序。我不使用celery beat,所以我在每个容器中部署了一个worker沿着django。但由于某种原因,这并不起作用,如果我进入pod并手动执行命令,那么一切都很好,但它不能通过dockerfile工作。
FROM python:3.10.2-slim-buster
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
RUN apt-get update && \
apt-get install -y -q \
openssl curl libpq-dev python3-dev build-essential && \
apt-get clean
ADD sizze /app
WORKDIR /app
RUN pip install --upgrade pip
COPY requirements.txt .
RUN pip install -r requirements.txt
EXPOSE 8000
CMD ["mkdir", "logs", "&&", "touch", "logs/error.log", "&&", "touch", "logs/access.log"]
CMD ["celery", "-A", "app.celery", "worker", "-l", "info", "--detach"]
CMD ["python", "manage.py", "migrate"]
CMD ["gunicorn", "--bind", ":8000", "--workers", "2", "--timeout", "300", "--error-logfile", "logs/error.log", "--access-logfile", "logs/access.log", "--capture-output", "--log-level", "debug", "app.wsgi"]
然后,如果我去pod并检查worker,他们不在那里
现在我正在运行celery 工人,一切都很好,为什么它不运行在dockerfile?
celery -A sizze.celery worker -l info --detach
celery@api-production-6c784b68d6-gn74d': {'ok': 'pong'}
1条答案
按热度按时间uidvcgyl1#
在一个Dockerfile中只能有一个CMD指令。如果您列出多个CMD,则只有最后一个CMD会生效。
来源https://docs.docker.com/engine/reference/builder/#cmd
我可以建议您创建包含所有命令的shell脚本,例如run.sh,并添加CMD [“run.sh”]