I’ve asked the same question on SO, but I feel that people from this forum are more concentrate on this topic. Here is the SO link, (link) and I’m coying the question here.
As the most important benefit of using docker is to keep dev and prod env to be the same so let’s rule out the option of using two different
Let’s say we have a Django application, and we use
gunicorn to serve for production and we have a dedicated apache2 as a reverse proxy(this apache2 is out of docker by design). So this application(docker-compose) has only two parts,
web (Django) and
db (mysql). There’s nothing wrong with the db part.
For the Django part, the dev routine without docker would be using venv and
python3 manage.py runserver or whatever shortcut that an IDE provides. We can happily change our code, the dev server is smart to pick up and change and reflect in no time.
Things get tricky when docker comes in since all source code should be packed into the image, this gives our dev a big overhead of recreating the image&container again and again. One might have the following solutions(which I found not elegant):
docker-compose.ymluse volume to mount source code folder into the container, so that all changes in the host source code folder will automatically reflect in the container, then
gunicornwill pick up the change and reflect. — This does remove most of the recreating container overhead, but we can’t use the same
docker-compose.ymlin production as this introduces a dependency to the source code on the host server.
I know there is a command line option to mount a host folder to the container, but to my knowledge, this option only exists in
docker-compose. So using a different command to bring the service up in different env is another dead end. ( I am not 100% sure about this as I’m still quite new to docker, please correct me if I’m wrong )
TLDR; How can I set up my env so that
- I use only one single
docker-compose.ymlfor both dev and prod
- I’m able to dev with live changes easily without recreating docker container
Thanks a lot!