<p>I want to create a nginx container that copies the content of my local machine /home/git/html into container /usr/share/nginx/html. However I cannot use Volumes and Mountpath, as my kubernetes cluster has 2 nodes.
I decided instead to copy the content from my github account. I then created this dockerfile:</p>
<pre><code>FROM nginx
CMD [&quot;apt&quot;, &quot;get&quot;, &quot;update&quot;]
CMD [&quot;apt&quot;, &quot;get&quot;, &quot;install&quot;, &quot;git&quot;]
CMD [&quot;git&quot;, &quot;clone&quot;, &quot;https://github.com/Sonlis/kubernetes/html&quot;]
CMD [&quot;rm&quot;, &quot;-r&quot;, &quot;/usr/share/nginx/html&quot;]
CMD [&quot;cp&quot;, &quot;-r&quot;, &quot;html&quot;, &quot;/usr/share/nginx/html&quot;]
</code></pre>
<p>The dockerfile builds correctly, however when I apply a deployment with this image, the container keeps restarting. I know that once a docker has done its job, it shutdowns, and then the deployment restarts it, creating the loop. However when applying a basic nginx image it works fine. What would be the solution ? I saw solutions running a process indefinitely to keep the container alive, but I do not think it is a suitable solution.</p>
<p>Thanks !</p>

Baptise
<p>You need to use <code>RUN</code> to perform commands when build a docker image, as mentioned in @tgogos comment. See the <a href="https://stackoverflow.com/questions/37461868/difference-between-run-and-cmd-in-a-dockerfile">refer</a>.</p>
<p>You can try something like that:</p>
<pre><code>FROM nginx
RUN apt-get update &amp;&amp; \
    apt-get install git
RUN rm -rf /usr/share/nginx/html &amp;&amp; \
    git clone https://github.com/Sonlis/kubernetes/html /usr/share/nginx/html

CMD [&quot;nginx&quot;, &quot;-g&quot;, &quot;daemon off;&quot;]
</code></pre>
<p>Also, I would like to recommend you to take a look in <a href="https://docs.docker.com/develop/develop-images/dockerfile_best-practices/" rel="nofollow noreferrer">this part of documentation</a> of how to optmize your image taking advantages of cache layer and multi-stages builds.</p>
