zoukankan      html  css  js  c++  java
  • 构建一个 预装 pm2 的 node 项目 docker 底包

    Dockerfile: 创建 dockerfile 文件, 命名为 dockerfile-yourProject-node.8.12.0-pm2

    # MAGE:     yourGroup/yourProject-node.8.12.0-pm2
    # VERSION:  1.0.0
    # AUTHOR:   ecalf
    
    # 基于网上公开的 docker 镜像构建,根据你的需要到 hub.docker.com 上找对应的镜像
    FROM mhart/alpine-node:8 MAINTAINER ecalf <ecalf@xxx.com> #backup Dockerfile COPY dockerfile-yourProject-node.8.12.0-pm2 ~/Dockerfile #whereis node RUN ln -s /usr/bin/node /usr/local/bin/node RUN ln -s /usr/bin/node /usr/sbin/node RUN ln -s /usr/bin/node /usr/lib/node # Setting time zone RUN apk update && apk add ca-certificates && apk add tzdata && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" > /etc/timezone #some module installed via cnpm of taobao RUN echo ';fsevents_binary_host_mirror=https://npm.taobao.org/mirrors/fsevents' >> ~/.npmrc RUN echo ';sass_binary_site=https://npm.taobao.org/mirrors/node-sass' >> ~/.npmrc RUN echo ';phantomjs_cdnurl=http://npm.taobao.org/mirrors/phantomjs' >> ~/.npmrc RUN echo ';electron_mirror=https://npm.taobao.org/mirrors/electron' >> ~/.npmrc RUN npm config set registry http://192.168.1.53:4873

    #npm install RUN npm install -g pm2 EXPOSE 80 CMD ["node" ,"-v"]

    创建文件夹, 把 dockerfile-yourProject-node.8.12.0-pm2 放进文件夹内,在命令行进入 该文件夹,执行下面命令构建底包,不要 在包含很多额外文件的文件夹内打包,否则准备docker上下文环境会花掉很长时间。

    docker build -t hub.docker.xxx.com/yourGroup/yourProject-node.8.12.0-pm2:1.0.0 -f dockerfile-yourProject-node.8.12.0-pm2 .

    构建项目的 Dockerfile 文件, 一个例子,具体根据自己项目具体情况来编写 

    # MAGE:     yourGroup/yourProject
    # VERSION:  5.8.0  
    # AUTHOR:   ecalf
    
    
    FROM hub.docker.xxx.com/yourGroup/yourProject-node.8.12.0-pm2:1.0.0
    
    MAINTAINER ecalf <ecalf@xxx.com>
    
    
    # This section for common define
    ENV WORK_DIR /home/project/www.xxx.com
    ENV LOG_DIR /data/log
    ENV CONFIG_DIR /home/project/node/www.xxx.com/confLocal
    
    
    # This section for import code & config
    RUN mkdir -p $WORK_DIR
    RUN mkdir -p $LOG_DIR 
    RUN mkdir -p $CONFIG_DIR
    
    
    WORKDIR $WORK_DIR
    COPY tar/xxx.com.tar.bz2 $WORK_DIR
    RUN tar -xjf xxx.com.tar.bz2
    RUN rm xxx.com.tar.bz2COPY conf/process.json $WORK_DIR
    
    
    EXPOSE 4305
    
    CMD ["pm2-docker", "start", "/home/project/www.xxx.com/process.json"]

    项目镜像打包命令, 从命令传入新镜像的 tag,脚本 命名为 buildDocker, 则执行  buildDocker 1.0.0

    #!/bin/sh
    
    tag=$1
    if [ 'n'$1 = 'n' ]; then
        echo 'please input tag as argument'
    else
        sudo docker build -t hub.docker.xxx.com/yourGroup/yourProject:${tag} .
    fi

    项目镜像的启动,从命令行传入要启动的镜像 tag,脚本 命名为 runDocker, 则执行  runDocker 1.0.0, 例子中设置了 环境配置文件夹、日志文件夹 的 挂载 

    #!/bin/sh
    
    tag=$1
    sudo docker run --name yourProject -p 14305:4305 -v /home/ecalf/work/docker/yourProject/config:/home/project/www.xxx.com/confLocal  -v /home/ecalf/work/docker/yourProject/logs:/home/project/www.xxx.com/logs -v /home/ecalf/work/docker/yourProject/log:/data/log -d hub.docker.xxx.com/yourGroup/yourProject:${tag}
  • 相关阅读:
    POJ 2778(自动机+矩阵幂乘(字符串果然是个坑爹玩应!))
    CF357D(规律题,不好想出来!)
    HDU 4107(线段树 特殊懒惰标记)g++ TLE,c++才过(呜呜呜呜)
    hdu 3954(线段树的特殊lazy操作-更新时才遍历!)
    CF354C(思路+(左区间++,1+右区间--思想))
    hdu3851(dp+区间范围很大且有循环的处理方法)
    CF119D(字符串-哈希求解(KMP求了半天,结果哈希更简单!))
    CF 353D
    HDU 4760 字典树(题意比较难理解)
    hdu3649(取石子博弈+dp)
  • 原文地址:https://www.cnblogs.com/ecalf/p/9996868.html
Copyright © 2011-2022 走看看