nuxt docker 化
如何将nuxt docker化?
-
在项目根目录创建
docker
文件夹,并创建dockerfile
文件# dockerfile FROM node:11.13.0-alpine AS builder MAINTAINER jiezai # create destination directory RUN mkdir -p /usr/src/nuxt-app WORKDIR /usr/src/nuxt-app # use taobao registry RUN npm config set registry https://registry.npm.taobao.org COPY nuxt-app/package.json nuxt-app/package-lock.json ./ # build necessary, even if no static files are needed, # since it builds the server as well RUN npm install --no-optional FROM node:11.13.0-alpine MAINTAINER jiezai # create destination directory RUN mkdir -p /usr/src/nuxt-app WORKDIR /usr/src/nuxt-app # use taobao registry RUN npm config set registry https://registry.npm.taobao.org COPY nuxt-app/ /usr/src/nuxt-app/ COPY --from=builder /usr/src/nuxt-app/node_modules ./node_modules #ENV NODE_ENV=production ENV HOST 0.0.0.0 # set app serving to permissive / assigned #ENV NUXT_HOST=127.0.0.1 # set app port ENV NUXT_PORT=5000 # expose 5000 on container EXPOSE 5000 RUN npm run build # start the app CMD [ "npm", "start" ]
-
构建镜像
直接在docker 目录下执行
docker build -t nuxt-demo .
命令构建镜像,记住最后面有个.
-
通过mvn直接执行
mvn clean install
命令构建镜像(不需要的跳过)
添加项目根目录下pom.ml
文件,可以通过mvn clean install
命令自动构建docker镜像(如不需要则跳过)<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.isuwang</groupId> <artifactId>isuwang-web</artifactId> <version>2.0.0</version> <build> <finalName>${project.artifactId}</finalName> <plugins> <plugin> <artifactId>maven-antrun-plugin</artifactId> <version>1.8</version> <executions> <execution> <id>copy files</id> <phase>package</phase> <configuration> <!-- copy child's output files into target/docker --> <tasks> <copy todir="${basedir}/docker/nuxt-app"> <fileset dir="${basedir}/"> <exclude name="**/node_modules/**"/> <exclude name="**/docker/**"/> <exclude name="**/target/**"/> </fileset> </copy> </tasks> </configuration> <goals> <goal>run</goal