Dockerfile 是这样的(直接复制的 node 官方的 Dockerfile 示例)
链接: https://nodejs.org/en/docs/guides/nodejs-docker-webapp/
#FROM node:12
FROM my-node-ubuntu-image
# Create app directory
WORKDIR /apps/express-upload
# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./
RUN npm install
# If you are building your code for production
# RUN npm ci --only=production
RUN ls -al
# Bundle app source
COPY . .
EXPOSE 8080
CMD [ "node", "app.js" ]
现在问题是:
使用官方一样的 base image node:12
就可以在 RUN ls -al
那一步看到有 node_modules
文件夹,
但是用我自己创建的 base image my-node-ubuntu-image
(是装有 node 的),就找不到 node_modules
文件夹了?
docker build 语句:
docker build . -t node-web-app:0.05
执行结果: (可以看到 npm install 是执行了的,但是下面的 RUN ls -al 没有 node_modules )
Sending build context to Docker daemon 121.1MB
Step 1/8 : FROM my-node-ubuntu-image
---> 4d66ffd553f3
Step 2/8 : WORKDIR /apps/express-upload
---> Using cache
---> 61e3227e0d01
Step 3/8 : COPY package*.json ./
---> 47e0df84b2e3
Step 4/8 : RUN npm install
---> Running in 55437825f54f
npm WARN nodejs@1.0.0 No description
npm WARN nodejs@1.0.0 No repository field.
added 224 packages from 267 contributors and audited 224 packages in 8.51s
found 3 vulnerabilities (1 low, 2 moderate)
run `npm audit fix` to fix them, or `npm audit` for details
Removing intermediate container 55437825f54f
---> a8e5ce1df24a
Step 5/8 : RUN ls -al
---> Running in a96450a9b1ba
total 76
drwxr-xr-x 2 root root 4096 Dec 3 07:17 .
drwxr-xr-x 3 root root 4096 Dec 3 07:17 ..
-rw-r--r-- 1 root root 63608 Dec 1 18:34 package-lock.json
-rw-r--r-- 1 root root 615 Dec 3 06:24 package.json
Removing intermediate container a96450a9b1ba
---> 12e7d8dea420
Step 6/8 : COPY . .
---> 60aa2971f746
Step 7/8 : EXPOSE 8080
---> Running in d9693d5e39c4
Removing intermediate container d9693d5e39c4
---> 3039a0c5d66c
Step 8/8 : CMD [ "node", "app.js" ]
---> Running in e925d8d9e250
Removing intermediate container e925d8d9e250
---> 69941e3a6915
Successfully built 69941e3a6915
Successfully tagged node-web-app:0.05
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.