title: Rebuild Docker container on file changes
body: <p>For running an ASP.NET Core application, I generated a dockerfile which build the application and copys the source code in the container, which is fetched by Git using Jenkins. So in my workspace, I do the following in the dockerfile: </p>
  
  <pre><code>WORKDIR /app
  COPY src src
  </code></pre>
  
  <p>While Jenkins updates the files on my host correctly with Git, Docker doesn't apply this to my image. </p>
  
  <p>My basic script for building:</p>
  
  <pre><code>#!/bin/bash
  imageName=xx:my-image
  containerName=my-container
  
  docker build -t $imageName -f Dockerfile  .
  
  containerRunning=$(docker inspect --format="{{ .State.Running }}" $containerName 2&gt; /dev/null)
  
  if [ "$containerRunning" == "true" ]; then
          docker stop $containerName
          docker start $containerName
  else
          docker run -d -p 5000:5000 --name $containerName $imageName
  fi
  </code></pre>
  
  <p>I tried different things like <code>--rm</code> and <code>--no-cache</code> parameter for <code>docker run</code> and also stopping/removing the container <em>before</em> the new one is build. I'm not sure what I'm doing wrong here. It seems that docker is updating the image correctly, as the call of <code>COPY src src</code> would result in a layer id and no cache call: </p>
  
  <pre><code>Step 6 : COPY src src
   ---&gt; 382ef210d8fd
  </code></pre>
  
  <p>What is the recommended way to update a container? </p>
  
  <p>My typical scenario would be: The application is running on the server in a Docker container. Now parts of the app are updated, e.g. by modifying a file. Now the container should run the new version. Docker seems to recommend building a new image instead of modifying a existing container, so I think the general way of rebuilding like I do is right, but some detail in the implementation has to be improved. </p>