docker
FROM node:lts-alpine as build-stage
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
WORKDIR /usr/src/app
#docker 参数传入构建环境变量
ARG NODE_ENV
#设置容器内的环境变量
ENV NODE_ENV $NODE_ENV
ADD . /usr/src/app
RUN npm config set registry="http://10.100.17.79:5006/repository/npm-group/"
RUN npm install
RUN npm run build
# production stage
FROM nginx:stable-alpine as production-stage
ARG NODE_ENV
ADD nginx/. /usr/src/app
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
COPY nginx/nginx.conf /etc/nginx/nginx.conf
RUN if [ $NODE_ENV == "dev" ] ; then cp /usr/src/app/nginx.development.conf /etc/nginx/conf.d/default.conf;echo 'nginx dev'; fi
RUN if [ $NODE_ENV == "test" ] ; then cp /usr/src/app/nginx.test.conf /etc/nginx/conf.d/default.conf;echo 'nginx test'; fi
RUN if [ $NODE_ENV == "production" ] ; then cp /usr/src/app/nginx.production.conf /etc/nginx/conf.d/default.conf;echo 'nginx production'; fi
COPY /usr/src/app/dist /usr/share/nginx/html
COPY /usr/src/app/src/dnotdelet /usr/share/nginx/html/dnotdelet
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45