evilmartians / ruby-on-whales

Ruby on Whales example and templates
MIT License
295 stars 26 forks source link

Use `RUN --mount` in `Dockerfile` for faster builds #21

Closed Envek closed 1 year ago

Envek commented 1 year ago

RUN --mount command in Dockerfile allows to get rid of cryptic cleanup of package installation intermediate data (package index and downloaded packages) to reduce Docker layer size by moving that data either to special build time volumes preserved between builds or to a tmpfs for data that doesn't need to be preserved.

The main advantage is that for repeated runs of apt-get update && apt-get install, it speeds up build by removing need to repeatedly download package index. Also it speeds up subsequent builds, as deb packages are cached between builds and can be used from the cache.

This feature is relatively new (2-3 years) and requires Docker Buildkit which is enabled by default starting with Docker Desktop 2.4.0.0 released 2 years ago in September 2020 (release notes for Docker Desktop for Windows and Docker Desktop for Mac):

Docker Desktop now enables BuildKit by default after a reset to factory defaults.

While there is open issue https://github.com/moby/moby/issues/40379 to enable it on Linux, it actually works on my machine (Docker client and engine version is 20.10.21) without any custom configuration.

palkan commented 1 year ago

Thanks!