3 ms·
Problem with docker is there if something early on changes then everything after needs to be rebuild. However with a build you might have A and B feed into C.
by quickthrower2 7y ago
Problem with docker is there if something early on changes then everything after needs to be rebuild.
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.
- caleblloyd 7y agoOne solution in Docker is multistage builds where A and B can be separated into intermediate images with results copied into C. 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.