title: How to edit code in a Docker container in development?
body: <p>I have all my websites' code under <code>/srv</code> in my containers.</p>
  
  <p>My Dockerfile downloads the code using git and makes it part of the image for easier deployment to production.</p>
  
  <p>But then how do I edit the code in development? I thought using volumes was the solution, eg: <code>-v /docker/mycontainer/srv:/srv</code>. But it overwrites the directory in the container. If it's the first time I run it it empties it because there's nothing in the host. So whatever I did in the Dockerfile was gets lost.</p>
  
  <p>There are also directories and files inside <code>/srv/myapp</code> that I want to be shared across the different versions of my app, eg: <code>/srv/myapp/user-uploads</code>. This is a <a href="http://astrails.com/blog/2008/12/17/deployment-process-requirements">common practice</a> in professional web development.</p>
  
  <p>So what can I do to be able to do all these things?:</p>
  
  <ul>
  <li>edit code in /srv in development</li>
  <li>share /srv/myapp/user-uploads across different versions</li>
  <li>let Dockerfile download the code. Doing "git clone" or "git pull" outside of Docker would defeat Docker's purpose in my opinion. Besides there are things that I can't run in the host, like the database migrations or other app-specific scripts.</li>
  </ul>
  
  <p>Is there a way to do a reverse volume mount? I mean make the container overwrite the host, instead of the opposite.</p>
  
  <p>I'm thinking one soluiton might be to copy /srv to /srv.deployment-copy before running the container's daemon. And then when I run the daemon check if /srv.deployment-copy exists and copy everything back to /srv. This way I can use /srv as a volume and still be able to deploy code to it with the Dockerfile. I'm already using aliases for all the docker commands so automating this won't be a problem. What do you think?</p>