在Docker容器中缺less`node_modules`
我正在使用下面的Dockerfile
为我的Node.js应用程序构buildDockerfile
:
FROM keymetrics/pm2:latest RUN apk add --no-cache --update alpine-sdk python # Bundle APP files COPY package.json . # Install app dependencies ENV NPM_CONFIG_LOGLEVEL warn RUN npm install RUN npm rebuild bcrypt --build-from-source COPY . . # Show current folder structure in logs RUN ls -al EXPOSE 3000 VOLUME /app/uploads CMD [ "pm2-docker", "start", "pm2.json" ]
问题是node_modules
文件夹不存在于从此映像创build的node_modules
容器中,因此应用程序遇到错误将无法运行。
我的.dockerignore
文件中有node_modules
,但是因为我在构build过程( RUN npm install
)中安装了必要的软件包,所以这不会引起问题。
那你为什么不在build中创build这个目录( Dockerfile
在RUN npm install
之前,在你的Dockerfile
添加下面一行)?
RUN mkdir <workdir>/node_modules
(将<workdir>
replace为keymetrics/pm2
映像的实际默认工作目录)