1.创建Dockerfile文件
# This file is a template, and might need editing before it works on your project.FROM node:8.9.3WORKDIR /usr/src/appARG NODE_ENVENV NODE_ENV $NODE_ENVCOPY package.json /usr/src/app/RUN npm install --registry=https://registry.npm.taobao.orgCOPY . /usr/src/appCMD [ "npm", "start" ]# replace this with your application's default portEXPOSE 80
2.创建.gitlab-ci.yml文件
before_script: #停止正在运行的容器 - "docker rm gpcmarket-ops-vue -f"job_test: script: #build镜像 - "docker build -t liyc/gpcmarket-ops-vue ." #运行对外端口80 - "docker run --name gpcmarket-ops-vue -d -p 80:80 liyc/gpcmarket-ops-vue" only: - test tags: - shared1
这样每次test分支有commit时会自动构建镜像并运行一个新的docker容器,对外端口80。