我经历了one of very few good dockerizing Vue.js tutorials还有一件事我不明白为什么在 Dockerfile
中是强制性的:
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json /usr/src/app/package.json #not sure though how it relates to PATH...
我只找到了一个解释 here其中说:
We expose all Node.js binaries to our PATH environment variable and copy our projects package.json to the app directory. Copying the JSON file rather than the whole working directory allows us to take advantage of Docker’s cache layers.
尽管如此,它并没有让我变得更聪明。谁能用简单的英语解释一下?
最佳答案
所以我认为这一行的好处是将来自 Docker 容器的 node_modules 路径添加到 PATH
的列表中s 在相关容器上。如果您使用的是 Mac(或我认为是 Linux)并运行:
$ echo $PATH
您应该会看到用于从终端运行全局命令的路径列表,即 gulp
, husky
, yarn
等等。上面的命令会将 node_modules 路径添加到 docker 容器中的 PATH 列表中,以便这些命令(如果需要)可以在容器内全局运行,它们将起作用。
关于node.js - Dockerizing Node.js 应用程序 - : ENV PATH/app/node_modules/. bin:$PATH 是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59275686/