Dockerfile配置

# docker build -t vue_app_image .
FROM node:12-slim

# system local config
RUN true \
  # debian china mirrors
  && sed -i 's/deb.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list \
  && sed -i 's/security.debian.org/mirrors.ustc.edu.cn/g' /etc/apt/sources.list \
  # timezone to china
  && ln -sf /usr/share/zoneinfo/PRC /etc/localtime

RUN apt-get update \
  && apt-get install -y \
  # node-sass 等编译依赖
  make gcc g++ python \
  # 命令行工具
  curl wget vim git

RUN true \
  # npm china mirrors
  && npm config set registry https://registry.npm.taobao.org \
  && npm config set disturl https://npm.taobao.org/dist \
  && npm config set sass_binary_site https://npm.taobao.org/mirrors/node-sass \
  && npm config set electron_mirror https://npm.taobao.org/mirrors/electron \
  && npm config set puppeteer_download_host https://npm.taobao.org/mirrors \
  && npm config set chromedriver_cdnurl https://npm.taobao.org/mirrors/chromedriver \
  && npm config set operadriver_cdnurl https://npm.taobao.org/mirrors/operadriver \
  && npm config set phantomjs_cdnurl https://npm.taobao.org/mirrors/phantomjs \
  && npm config set selenium_cdnurl https://npm.taobao.org/mirrors/selenium \
  # fix yarn permission denied  https://github.com/nodejs/docker-node/issues/661
  && chmod a+x /usr/local/bin/yarn \
  # yarn china mirrors  https://github.com/nodejs/docker-node/issues/386
  && yarn config set registry https://registry.npm.taobao.org || true

RUN true \
    && npm install -g @vue/cli

RUN mkdir /workspace

WORKDIR /workspace

# 给这个目录执行权限,x是执行权限
RUN chmod +x /workspace

#VOLUME /workspace

EXPOSE 8080

CMD ["/bin/sh"]

生成镜像

docker build -t vue_app_image .  

开发环境 docker-compose.yml

version: '3'
services:
  dev:
    image: vue_app_image
    ports:
      - "8080:8080"
#    restart: always
    volumes:
      - ./:/workspace
    stdin_open: true
    tty: true
    # command: "yarn serve"

启动

docker-compose up

进入容器

docker exec -it {your docker name} /bin/sh
yarn install
yarn serve