Docker Community Forums

Share and learn in the Docker community.

App code inside image or as a volume?

When I read tutorials online, people tend to put their application code inside the docker image. I see the point, you just send that single image anywhere and it will work without specifying anything.

However in development, it means that you rebuild the image 100 times a day every times you want to test something.

Having that in mind, I feel it might be better to mount the app code as a volume inside the container and just re-run the same environment image to test the code.

In that case however, it means that in production you have to fetch the app code and the docker image, checkout the code version, etc.

I’m not sure what would be best here.

What would the docker community recommend?

It depends what your language of choice brings to the table.

You might want to create a base image wich includes all your dependencies (like an appserver) and your entrypoint scripts to bend the congfiguration during container start. You will only need to create it once - though, repeat a rebuild with updated dependencies as often, as your patch management strategie requires you to.

Then create a new image, based on your previously created base image, and just add your code or binaries to this image. Instead of building the whole image from the scatch, you will end up in just builing an image layer holding the additional data of your code.

Though, some languages do allow some fency stuff: e.g. with java webapps, you can use maven plugins to directly deploy your application directly into the application server inside the container…

Thank you @meyay this seems like a perfect way to go.

I’ll give it a try and see how the workflow feels.