<p>My docker-compose creates 3 containers - django, celery and rabbitmq. When i run the following commands -&gt; docker-compose build and docker-compose up, the containers run successfully.</p>
<p>However I am having issues with deploying the image. The image generated has an image ID of 24d7638e2aff. For whatever reason however, if I just run the command below, nothing happens with an exit 0. Both the django and celery applications have the same image id.</p>
<pre><code>docker run 24d7638e2aff
</code></pre>
<p><a href="https://i.stack.imgur.com/W0yCJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/W0yCJ.png" alt="" /></a></p>
<p>This is not good, as I am unable to deploy this image on kubernetes. My only thought is that the dockerfile has been configured wrongly, but i cannot figure out what is the cause</p>
<p>docker-compose.yaml</p>
<pre><code>version: &quot;3.9&quot;
services:
  django:
    container_name: testapp_django
    build:
      context: .
      args:
        build_env: production
    ports:
      - &quot;8000:8000&quot;
    command: &gt;
      sh -c &quot;python manage.py migrate &amp;&amp;
             python manage.py runserver 0.0.0.0:8000&quot;

    volumes:
      - .:/code
    links:
      - rabbitmq
      - celery

  rabbitmq:
    container_name: testapp_rabbitmq
    restart: always
    image: rabbitmq:3.10-management
    ports:
      - &quot;5672:5672&quot; # specifies port of queue
      - &quot;15672:15672&quot; # specifies port of management plugin

  celery:
    container_name: testapp_celery
    restart: always
    build:
      context: .
      args:
        build_env: production
    command: celery -A testapp worker -l INFO -c 4
    depends_on:
      - rabbitmq
</code></pre>
<p>Dockerfile</p>
<pre><code>ARG PYTHON_VERSION=3.9-slim-buster

# define an alias for the specfic python version used in this file.
FROM python:${PYTHON_VERSION} as python

# Python build stage
FROM python as python-build-stage

ARG build_env

# Install apt packages
RUN apt-get update &amp;&amp; apt-get install --no-install-recommends -y \
  # dependencies for building Python packages
  build-essential \
  # psycopg2 dependencies
  libpq-dev

# Requirements are installed here to ensure they will be cached.
COPY ./requirements .

# Create Python Dependency and Sub-Dependency Wheels.
RUN pip wheel --wheel-dir /usr/src/app/wheels  \
  -r ${build_env}.txt


# Python 'run' stage
FROM python as python-run-stage

ARG build_env
ARG APP_HOME=/app

ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV BUILD_ENV ${build_env}

WORKDIR ${APP_HOME}

RUN addgroup --system appuser \
    &amp;&amp; adduser --system --ingroup appuser appuser

# Install required system dependencies
RUN apt-get update &amp;&amp; apt-get install --no-install-recommends -y \
  # psycopg2 dependencies
  libpq-dev \
  # Translations dependencies
  gettext \
  # git for GitPython commands
  git-all \
  # cleaning up unused files
  &amp;&amp; apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
  &amp;&amp; rm -rf /var/lib/apt/lists/*

# All absolute dir copies ignore workdir instruction. All relative dir copies are wrt to the workdir instruction
# copy python dependency wheels from python-build-stage
COPY --from=python-build-stage /usr/src/app/wheels  /wheels/

# use wheels to install python dependencies
RUN pip install --no-cache-dir --no-index --find-links=/wheels/ /wheels/* \
  &amp;&amp; rm -rf /wheels/


COPY --chown=appuser:appuser ./docker_scripts/entrypoint /entrypoint
RUN sed -i 's/\r$//g' /entrypoint
RUN chmod +x /entrypoint


# copy application code to WORKDIR
COPY --chown=appuser:appuser . ${APP_HOME}

# make appuser owner of the WORKDIR directory as well.
RUN chown appuser:appuser ${APP_HOME}
USER appuser

EXPOSE 8000

ENTRYPOINT [&quot;/entrypoint&quot;]
</code></pre>
<p>entrypoint</p>
<pre><code>#!/bin/bash

set -o errexit
set -o pipefail
set -o nounset

exec &quot;$@&quot;
</code></pre>
<p>How do I build images of these containers so that I can deploy them to k8s?</p>

<p>The Compose <code>command:</code> overrides the Dockerfile <code>CMD</code>.  <code>docker run</code> doesn't look at the <code>docker-compose.yml</code> file at all, and <code>docker run</code> with no particular command runs the image's <code>CMD</code>.  You haven't declared anything for that, which is why the container exits immediately.</p>
<p>Leave the entrypoint script unchanged (or even delete it entirely, since it doesn't really do anything).  Add a <code>CMD</code> line to the Dockerfile</p>
<pre class="lang-bash prettyprint-override"><code>CMD python manage.py migrate &amp;&amp; python manage.py runserver 0.0.0.0:8000
</code></pre>
<p>Now plain <code>docker run</code> as you've shown it will attempt to start the Django server.  For the Celery container, you can still pass a command override</p>
<pre class="lang-bash prettyprint-override"><code>docker run -d --net ... your-image \
  celery -A testapp worker -l INFO -c 4
</code></pre>
<p>If you do deploy to Kubernetes, and you keep the entrypoint script, then you need to use <code>args:</code> in your pod spec to provide the alternate command, not <code>command:</code>.</p>
