在本机无感知地调用镜像中的 node 和 npm 命令的解决方案,使用alpine制作,latest 为 node22。
/Users/me/code/aaa,则共享 /Users/me/code目录)docker run --name node -itd -p 8080-8085:8080-8085 -v 你的项目父级目录:你的项目父级目录 tomatocuke/node:latest
alias node='docker exec -it -w $(pwd) node node'
alias npm='docker exec -it -w $(pwd) node npm'
alias pnpm='docker exec -it -w $(pwd) node pnpm'
node 和 npm 相关的命令了。Could not open input file 请检查你的文件夹映射是否正确。 本机目录映射到容器中的路径应该一致,才能保证 -w $(pwd) 的正确性。spawn xdg-open ENOENT 是因为容器内无法自动打开浏览器,把 vite.config.js 或之类的配置中的 server - open 改为 false。pnpm 镜像源,进入容器内更改。 可以改为淘宝镜像源 pnpm config set registry https://registry.npmmirror.com/http://127.0.0.1:9000 来连接到后端服务,改用 http://host.docker.internal:9000 这样Content type
Image
Digest
sha256:afee68ca4…
Size
41 MB
Last updated
over 1 year ago
docker pull tomatocuke/node