title: How to edit files in stopped/not starting docker container
body: <p>Trying to fix errors and debug problems with my application that is split over several containers, I frequently edit files in containers:</p>
  
  <ul>
  <li><p>either I am totally lazy and install nano and edit directly in container or</p></li>
  <li><p>I docker cp the file out of the container, edit it, copy it back and restart the container</p></li>
  </ul>
  
  <p>Those are intermediate steps before coming to new content for container build, which takes a lot longer than doing the above (which of course is only intermediate/fiddling around).</p>
  
  <p>Now I frequently break the starting program of the container, which in the breaking cases is either a node script or a python webserver script, both typically fail from syntax errors.</p>
  
  <p>Is there any way to save those containers? Since they do not start, I cannot docker exec into them, and thus they are lost to me. I then go the rm/rmi/build/run route after fixing the offending file in the build input.</p>
  
  <p><strong>How can I either edit files in a stopped container, or cp them in or start a shell in a stopped container - anything that allows me to fix this container?</strong></p>
  
  <p>(It seems a bit like working on a remote computer and breaking the networking configuration - connection is lost "forever" this way and one has to use a fallback, if that exists.)</p>
  
  <p><a href="https://stackoverflow.com/questions/24553790/how-to-edit-docker-container-files-from-the-host">How to edit Docker container files from the host?</a> looks relevant but is outdated.</p>