Docker pros and cons including the code into the container or sharing it with the volume

Hey there,

I’m wondering what are the pros and cons of putting the source code into the container through COPY or ADD vs. sharing them with a volume.

Here’s what I see:

COPY pros:

  • container is fully autonomous
  • can be sent to hub
  • easy to replace
  • no share issue between instances/race conditions
  • no need to setup git and the repo on the server

COPY cons:

  • heavy containers
  • longer build/deployment time
  • introduces differences between local/production config

As for me the last point (local/production environment closeness) has always been the most important one, hence I have always been in favor of using volumes, but I’m wondering what are the best practices, if there are reasons I would forget that would override any other and cut the debate short.

Thanks for your insights.