I have all my websites' code under /srv
in my containers.
My Dockerfile downloads the code using git and makes it part of the image for easier deployment to production.
But then how do I edit the code in development? I thought using volumes was the solution, eg: -v /docker/mycontainer/srv:/srv
. 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.
There are also directories and files inside /srv/myapp
that I want to be shared across the different versions of my app, eg: /srv/myapp/user-uploads
. This is a common practice in professional web development.
So what can I do to be able to do all these things?:
- edit code in /srv in development
- share /srv/myapp/user-uploads across different versions
- 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.
Is there a way to do a reverse volume mount? I mean make the container overwrite the host, instead of the opposite.
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?