// Gzip off by default as many popular static hosts such as // Surge or Netlify already gzip all static assets for you. // Before setting to `true`, make sure to: // npm install --save-dev compression-webpack-plugin productionGzip: false, productionGzipExtensions: ['js', 'css'],
// Run the build command with an extra argument to // View the bundle analyzer report after build finishes: // `npm run build --report` // Set to `true` or `false` to always turn it on or off bundleAnalyzerReport: process.env.npm_config_report } }
# install simple http server for serving static content RUN npm install -g http-server
# make the 'app' folder the current working directory WORKDIR /app
# copy both 'package.json' and 'package-lock.json' (if available) COPY package*.json ./
# install project dependencies RUN npm install
# copy project files and folders to the current working directory (i.e. 'app' folder) COPY . .
# build app for production with minification RUN npm run build
EXPOSE 8080 CMD [ "http-server", "dist" ]
编译docker镜像
进入项目的根目录,执行打包命令:
1 2
# 在docker中myvue根目录下执行命令 docker build -t myvue .
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
86153@steven MINGW64 /d/shixun1/wpro/myvue (master) $ docker build -t myvue . Sending build context to Docker daemon 202.1MB Step 1/9 : FROM node:lts-alpine lts-alpine: Pulling from library/node cbdbe7a5bc2a: Pull complete 4c504479294d: Pull complete 1e557b93d557: Pull complete 227291017118: Pull complete Digest: sha256:5a940b79d5655cc688cfb319bd4d0f18565bc732ae19fab6106daaa72aeb7a63 Removing intermediate container 5317abe3649b ---> 2ddb8a0e3225 Successfully built 2ddb8a0e3225 Successfully tagged myvue:latest SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.
系统会自动根据脚本进行安装依赖,第一次也需要等待一段时间。
打包完成后,执行:
1
docker images
可以看到前端镜像的体积要小一点:
1 2 3 4
86153@steven MINGW64 /d/shixun1/wpro/myvue (master) $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE myvue latest 917d1c69f10f 23 hours ago 539MB