In this blog, we’re trying to answer the question of how to maintain our source code in a collaborative environment when using Docker. Normally, we’d use a source control tool such as SVN or Git. However, it isn’t straight forward how to use such tools in a dockerized environment.
Let’s emphasize the distinction between docker and git. Docker provides a platform to run our applications; such as LAMP or MEAN stack for web development. On the other hand, git is a source control software to track changes in a collaborative environment.
IMHO I think the best solution is using Volume Mapping
Also I think it would be better if you have the code it self in a separate container created from a very slim image like alpine.
But you should worry how to prevent this container from exiting, as there would be no running process inside, so it would exit instantly
You can search for a script called container discovery wrapper
and in your Docker file you can have something like
ADD LOCAL_PATH/container-discovery-wrapper /bin/container-discovery-wrapper RUN chmod +x /bin/container-discovery-wrapper CMD /bin/container-discovery-wrapper \ --command="/root/block-indefinitely" \ --service-name="codebase" \ --service-exposed-port=999 \ --discovery-server="$DISCOVERY_SERVER"