nodejs 版本dockerfile 文件制作,和常用命令
Dockerfile 如下
官方的node6.3的版本有点难下载,建议去网易蜂巢 https://c.163.com/hub
pull hub.c.163.com/library/node:6.9
修改镜像的tag : docker tag 45b81ae12746 node:6.9
From node:6.9 RUN npm install pm2 -g --registry=https://registry.npm.taobao.org RUN mkdir -p /usr/src/node-app RUN mkdir -p /usr/src/node-app/src RUN mkdir -p /usr/src/node-app/server WORKDIR /usr/src/node-app COPY src/. /usr/src/node-app/src/ COPY server/. /usr/src/node-app/server/ COPY .babelrc /usr/src/node-app/ COPY app.js /usr/src/node-app/ COPY dev-server.js /usr/src/node-app/ COPY gulpfile.js /usr/src/node-app/ COPY package.json /usr/src/node-app/ COPY pm2.json /usr/src/node-app/ COPY static_conf.js /usr/src/node-app/ COPY webpack.config.js /usr/src/node-app/ RUN npm install --registry=https://registry.npm.taobao.org RUN npm run build EXPOSE 5000 CMD ["npm", "run", "release"]
npm run release 代码 pm2 startOrGracefulReload ./pm2.json --no-daemon
pm2.json 代码如下
[{ "name" : "clms-node", "script" : "app.js", "error_file" : "app-err.log", "out_file" : "app-out.log", "pid_file" : "app.pid", "instances": 2 }]
创建镜像 docker build --tag="node/clms-node:v20" ./
启动镜像 sudo docker run -d -p 5003:5000 -e NODE_ENV=dev2 node/clms-node:v20
--设置环境变量 -e NODE_ENV=dev2 ,nodejs代码 获取环境变量如下 process.env.NODE_ENV