Skip to content

Instantly share code, notes, and snippets.

@akkuman
Last active October 25, 2023 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akkuman/faf190527dd5d5203aeda340c5b88d09 to your computer and use it in GitHub Desktop.
Save akkuman/faf190527dd5d5203aeda340c5b88d09 to your computer and use it in GitHub Desktop.
前端项目Dockerfile
upstream web_http {
server ${HTTP_PROXY_PASS};
}
server {
listen 80;
server_name localhost;
server_tokens off;
root /bin/www;
client_header_buffer_size 10240k;
large_client_header_buffers 4 10240k;
location /prod-api/ {
proxy_pass http://web_http/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_connect_timeout 1200s;
proxy_read_timeout 1200s;
proxy_send_timeout 1200s;
client_max_body_size 1024m;
proxy_redirect off;
proxy_set_header Host $http_host;
}
}
FROM --platform=linux/amd64 node:12-alpine as build
USER node
WORKDIR /app
ENV NPM_CONFIG_PREFIX=/home/node/.npm-global \
PATH=$PATH:/home/node/.npm-global/bin
COPY package*.json ./
RUN npm install -g mirror-config-china --registry=https://registry.npmmirror.com && \
npm install
COPY . .
RUN npm run build
FROM nginx:stable-alpine
COPY --from=build /app/build /bin/www
# 从nginx 1.11 开始默认支持 template,详见 https://hub.docker.com/_/nginx
COPY nginx/default.conf.template /etc/nginx/templates/default.conf.template
EXPOSE 80
CMD [ "nginx", "-g", "daemon off;" ]
# 含有github镜像加速
FROM --platform=linux/amd64 node:13-alpine as builder
USER root
WORKDIR /app
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.sjtug.sjtu.edu.cn/g' /etc/apk/repositories && \
apk --no-cache add git
# https://blog.csdn.net/CaptainJava/article/details/104540240
# 针对 github.com/adobe-webplatform/eve 安装失败
RUN git config --global --add url."https://ghproxy.com/https://github.com/".insteadOf git://github.com/ && \
# https://github.com/PanJiaChen/vue-element-admin/issues/3491
# vue-element-admin 中的 tui-editor 依赖 github.com/nhn/raphael,经常性安装失败,此处使用github镜像
git config --global --add url."https://ghproxy.com/https://github.com/".insteadOf https://github.com/ && \
npm install -g --unsafe-perm=true --allow-root mirror-config-china --registry=https://registry.npmmirror.com
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build:prod
FROM nginx:1.23-alpine
COPY --from=builder /app/dist /app/dist
COPY nginx/default.conf.template /etc/nginx/templates/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment