<p>I have a k8s cluster where I deploy my django application. I don't use celery beat so I deploy a worker in every container along with django. But for some reason this doesn’t work, if I go into the pod and execute the command manually, then everything is fine, but it doesn’t work through the dockerfile.</p>
<pre><code>FROM python:3.10.2-slim-buster

# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

RUN apt-get update &amp;&amp; \
  apt-get install -y -q \
  openssl curl libpq-dev python3-dev build-essential &amp;&amp; \
  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 [&quot;mkdir&quot;, &quot;logs&quot;, &quot;&amp;&amp;&quot;, &quot;touch&quot;, &quot;logs/error.log&quot;, &quot;&amp;&amp;&quot;, &quot;touch&quot;, &quot;logs/access.log&quot;]
CMD [&quot;celery&quot;, &quot;-A&quot;, &quot;app.celery&quot;, &quot;worker&quot;, &quot;-l&quot;, &quot;info&quot;, &quot;--detach&quot;]
CMD [&quot;python&quot;, &quot;manage.py&quot;, &quot;migrate&quot;]
CMD [&quot;gunicorn&quot;, &quot;--bind&quot;, &quot;:8000&quot;, &quot;--workers&quot;, &quot;2&quot;, &quot;--timeout&quot;, &quot;300&quot;, &quot;--error-logfile&quot;, &quot;logs/error.log&quot;, &quot;--access-logfile&quot;, &quot;logs/access.log&quot;, &quot;--capture-output&quot;, &quot;--log-level&quot;, &quot;debug&quot;, &quot;app.wsgi&quot;]
</code></pre>
<p>Then if I go to the pod and check the workers, they are not there<a href="https://i.stack.imgur.com/Thuo7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Thuo7.png" alt="enter image description here" /></a></p>
<p>Now I'm running celery worker and everything is fine, why doesn't it run in dockerfile?</p>
<pre><code>celery -A sizze.celery worker -l info --detach
celery@api-production-6c784b68d6-gn74d': {'ok': 'pong'}
</code></pre>

Kabiljan Tanaguzov
<blockquote>
<p>There can only be one CMD instruction in a Dockerfile. If you list
more than one CMD then only the last CMD will take effect.</p>
</blockquote>
<p>source <a href="https://docs.docker.com/engine/reference/builder/#cmd" rel="nofollow noreferrer">https://docs.docker.com/engine/reference/builder/#cmd</a></p>
<p>I can suggest you to create shell script containing all you commands e.g. run.sh
and add <strong>CMD [&quot;run.sh&quot;]</strong></p>
