Dockfile文件
安装依赖,打包,配置NGINX代理,最后把打完的包复制到服务器相应的文件夹下,构建镜像成功。
# syntax = docker/dockerfile:experimental
FROM xx.xx.xx.xx/public/node:16.14.2 as builder
# LABEL maintainer="elementwin"
WORKDIR /app
COPY package.json .
COPY package-lock.json .
RUN npm config set proxy http://xx.xx.xx.xx:端口号 \
RUN npm config set registry http://registry.npm.taobao.org
RUN npm install
COPY . .
ARG BUILD_ENV="production"
RUN npm run build:${BUILD_ENV}
# Build app
FROM xx.xx.xx.xx/public/nginx:1.24.0-tools as app
ENV TZ="Asia/Shanghai"
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo "Asia/Shanghai" >> /etc/timezone
WORKDIR /app
RUN mkdir -p /app/dist
ADD prod-nginx.conf /etc/nginx/conf.d/app.conf
COPY --from=builder /app/dist /app/dist
VOLUME ["/opt", "/app"]
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
NGINX文件
# admin.cloud.elementwin.com
server {
client_max_body_size 200m;
client_body_buffer_size 128k;
listen 80 default_server;
server_name _;
gzip on;
gzip_buffers 4 16k;
gzip_comp_level 6;
gzip_vary on;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
location / {
client_max_body_size 200m;
client_body_buffer_size 128k;
proxy_send_timeout 300;
proxy_read_timeout 300;
proxy_connect_timeout 600;
proxy_buffering on;
proxy_buffer_size 1M;
proxy_buffers 8 1M;
proxy_busy_buffers_size 1M;
proxy_temp_file_write_size 1M;
root /app/dist;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
location /api/ {
proxy_pass http://xx.xx.xx.xxx:端口号/;
}
}