# 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
复制相关的程序代码
# Bundle app sourceCOPY . .
绑定相关的端口号
EXPOSE 8080
创建持久化的命令,让系统在前台运行。
CMD [ "node", "server.js" ]
最后Dockerfile构建如下
FROM node:12# Create app directoryWORKDIR /usr/src/app# 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# Bundle app sourceCOPY . .EXPOSE 8080CMD [ "node", "server.js" ]