1、拷贝express应用目录拷到服务器某个目录,如/home/leyi/front_app_docker
2、新建一个pm2的配置文件preocess.json,配置如下:
{
"apps" : [{
"name" : "appName", //应用名称
"script": "./bin/www", //程序入口
"cwd": "./", //根目录
"watch":[
"bin",
"public",
"routes",
"views"
],//需要监控的目录
"error_file":"./logs/app-err.log",//错误输出日志
"out_file":"./logs/app-out.log", //日志
"log_date_format":"YYYY-MM-DD HH:mm Z" //日期格式
}]
}
3、新建Dockerfile文件,配置如下:
# 依赖pm2镜像
FROM keymetrics/pm2:latest-alpine
# Bundle APP files
RUN mkdir -p /home/front_app_dir
WORKDIR /home/front_app_dir
# Bundle app source
COPY . /home/front_app_dir
RUN npm install
# Install app dependencies
ENV NPM_CONFIG_LOGLEVEL warn
RUN npm install --production
# Show current folder structure in logs
RUN ls -al -R
EXPOSE 3000
CMD [ "pm2-runtime", "start", "process.json" ]
4、构建镜像 docker build -t appName .
5、docker run -d -p 8888:3000 镜像id
6、docker ps 查看已启动的容器 docker images -a 列出所有镜像