COPY Gemfile Gemfile.lock /src
RUN bundle install
even if they don't use docker to run application in prod, it can be [ab]used to perform efficient build layer (build step) caching and distribution. COPY Gemfile Gemfile.lock /src
RUN bundle install
even if they don't use docker to run application in prod, it can be [ab]used to perform efficient build layer (build step) caching and distribution.However with a build you might have A and B feed into C. If A changes and B hasn't you want to just build A and get B from cache.
A pattern that I like to use is two multistage build Dockerfiles- `dev` and `prod`.
The `dev` image has 2 stages. The first stage copies only files required by the package manager, such as `package.json` into another directory using a combination of `find` and `cp --parents`, then restores dependencies. The second stage copies the dependencies from the first stage and overlays source code. The `dev` image is then instantiated to run all tests.
The `prod` image also has 2 stages. The first stage starts with the `dev` image and publishes a production bundle to a directory. The second stage starts with a clean image and copies the production bundle from the first stage.