使用 Podman
Sharing files between a container and the host Btrfs filesystem#
注意
此方法仅适用于 Podman 支持的写时复制文件系统,例如 Btrfs。对于其他文件系统,例如 Ext4,pnpm 将复制文件。
Podman 支持像 Btrfs 这样的写时复制文件系统。通过 Btrfs,容器运行时为其挂载的卷创建实际的 Btrfs 子卷。 pnpm can use this behavior to reflink the files between different mounted volumes.
要在主机和容器之间共享文件,请将主机上的 store 目录和 node_modules 目录挂载到容器中。这允许容器内的 pnpm 自然地重用主机中的文件作为引用链接。
important
仅将宿主机的 pnpm 存储挂载到你信任的容器中。拥有挂载存储写入权限的容器,可能会影响后续复用该存储的安装操作。
以下是用于演示的示例容器设置:
Declare Node.js in devEngines.runtime in your package.json. The pnpm install command below will install the declared version automatically.
Dockerfile
FROM ghcr.io/pnpm/pnpm:11
WORKDIR /app
VOLUME [ "/pnpm-store", "/app/node_modules" ]
RUN pnpm config --global set store-dir /pnpm-store
# You may need to copy more files than just package.json in your code
COPY package.json /app/package.json
RUN pnpm install
RUN pnpm run build
运行以下命令来构建 podman 镜像:
podman build . --tag my-podman-image:latest -v "$HOME/.local/share/pnpm/store:/pnpm-store" -v "$(pwd)/node_modules:/app/node_modules"