Docker recipes- modifying code inside containers

Docker's official documentation and tutorials show us a technique to modify a project's source code inside a running container. This is done by mounting the folder from the host into the container.

In the docker volumes tutorial, the technique can be implied from:

docker run -d -P --name web -v /src/webapp:/opt/webapp training/webapp python

A more detailed explanation is given in the docker compose docs:

" Mounts the project directory on the host to /code inside the container allowing you to modify the code without having to rebuild the image. "

The above explanation dates backs as early as Jan 2014. Aside of the official docs, this technique is also discussed in forums. All of these references might suggest that the practice of modifying code inside containers has a justification.

There is no justification for modifying code inside containers

When your Dockerfile produces optimized docker images and layers, a code modification of your app or service will affect the top most layers. Essentially only the changed source gets built and uploaded to your registry, while the rest of the layers are served from cache. Therefore, building and uploading a new image after modifying source code should take a few seconds (More on optimizing images, and specifically in NodeJS).

Once your image is optimized and upload time nears zero, a little investment in a basic CI flow will leave no motivation for the mounting technique.

"But I need livereload to develop client side code"

Then work locally and isolated with Mock API's where needed. No need to develop client side code inside a full running deployment in the first place.