使用 Podman
在容器和主机 Btrfs 文件系统之间共享文件
¥Sharing Files Between a Container and the Host Btrfs Filesystem
此方法仅适用于 Podman 支持的写时复制文件系统,例如 Btrfs。对于其他文件系统,例如 Ext4,pnpm 将复制文件。
¥This method only works on copy-on-write filesystems supported by Podman, such as Btrfs. For other filesystems, like Ext4, pnpm will copy the files instead.
Podman 支持 Btrfs 等写时复制文件系统。使用 Btrfs,容器运行时为其安装的卷创建实际的 Btrfs 子卷。pnpm 可以利用此行为来重新链接不同已安装卷之间的文件。
¥Podman support copy-on-write filesystems like Btrfs. With Btrfs, container runtimes create actual Btrfs subvolumes for their mounted volumes. pnpm can leverage this behavior to reflink the files between different mounted volumes.
要在主机和容器之间共享文件,请将主机上的 store 目录和 node_modules
目录挂载到容器上。这允许容器内的 pnpm 自然地重用主机中的文件作为引用链接。
¥To share files between the host and the container, mount the store directory and the node_modules
directory from the host to the container. This allows pnpm inside the container to naturally reuse the files from the host as reflinks.
以下是用于演示的示例容器设置:
¥Below is an example container setup for demonstration:
FROM node:20-slim
# corepack is an experimental feature in Node.js v20 which allows
# installing and managing versions of pnpm, npm, yarn
RUN corepack enable
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
WORKDIR /app
RUN pnpm install
RUN pnpm run build
运行以下命令来构建 podman 镜像:
¥Run the following command to build the podman image:
podman build . --tag my-podman-image:latest -v "$HOME/.local/share/pnpm/store:/pnpm-store" -v "$(pwd)/node_modules:/app/node_modules"