<p>I have a Django app and use Celery for background tasks. </p>

<p>For deploying, I use Docker with Kubernetes.</p>

<p>Deployment is automatized with Jenkins.</p>

<p>All is good, however I feel like this can be drastically optimized.</p>

<p>The problem is that Jenkins builds almost the same images for a django app and 5 celery workers. The only difference they have is the entry point. Django app image starts gunicorn, celery container starts, well, celery.</p>

<p>What is the best practice to build almost the same images?</p>

<p>I would optimally like to build the same image several times and indicate the entrypoint during the build process.</p>

<p>Thank you for any help.</p>

<p>An option that comes to mind is to have the same entrypoint for all the images and then, using environment variables for example, have a logic in the entrypoint code that will launch one program or the other. Here's an extremely simple example.</p>

<pre><code>if [ $ROLE == "worker" ];then
    program_1
else
    profram_2
fi
</code></pre>

<p>Another option could be using the same entrypoint and then be able to select the exact program using the <code>command</code> argument. Find an example here: <a href="https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/</a>. An example Dockerfile and app-entrypoint.sh here</p>

<p><a href="https://github.com/bitnami/bitnami-docker-wordpress/blob/master/4/Dockerfile" rel="nofollow noreferrer">https://github.com/bitnami/bitnami-docker-wordpress/blob/master/4/Dockerfile</a>
<a href="https://github.com/bitnami/bitnami-docker-wordpress/blob/master/4/rootfs/app-entrypoint.sh" rel="nofollow noreferrer">https://github.com/bitnami/bitnami-docker-wordpress/blob/master/4/rootfs/app-entrypoint.sh</a></p>
