使用 Docker
備註
在建置時期,您無法在Docker容器與主機檔案系統間建立參照連結 (reflink) 或硬連結 (hard link)。 但您仍可透過 BuildKit 的 cache mount 功能,在不同組建間共享快取。 Alternatively, you may use podman because it can mount Btrfs volumes during build time.
最小化 Docker 映像尺寸及 建置時間
- Use a small image, e.g.
node:XX-slim. - 盡可能利用多階段建置。
- 利用 BuildKit 快取掛載區功能。
例一:在 Docker 容器中建置軟體包
Since devDependencies is only necessary for building the bundle, pnpm install --prod will be a separate stage
from pnpm install and pnpm run build, allowing the final stage to copy only necessary files from the earlier
stages, minimizing the size of the final image.
.dockerignore
node_modules
.git
.gitignore
*.md
dist