xiaoju-survey/Dockerfile

42 lines
1.5 KiB
Docker
Raw Normal View History

2023-11-02 12:12:37 +00:00
# 镜像集成
FROM node:18-slim AS builder
2023-11-02 12:12:37 +00:00
WORKDIR /builder
2023-11-02 12:12:37 +00:00
# 复制文件到工作区间
COPY web/ /builder/web/
COPY server/ /builder/server/
2023-11-02 12:12:37 +00:00
RUN sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list.d/debian.sources && \
npm config set registry https://registry.npmmirror.com && \
apt-get update && apt-get install -y build-essential && \
cd /builder/web && npm install && npm run build-only && \
cd /builder/server && npm install && npm run build
2023-11-02 12:12:37 +00:00
FROM node:18-slim
2024-05-20 10:37:12 +00:00
# 设置工作区间
WORKDIR /xiaoju-survey
# 安装nginx
RUN sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list.d/debian.sources && \
npm config set registry https://registry.npmmirror.com && \
apt-get update && apt-get install -y nginx
# 仅复制运行需要的文件到工作区间
COPY --from=builder /builder/web/dist/ /xiaoju-survey/web/dist/
COPY --from=builder /builder/server/dist/ /xiaoju-survey/server/dist/
COPY --from=builder /builder/server/node_modules/ /xiaoju-survey/server/node_modules/
COPY --from=builder /builder/server/public/ /xiaoju-survey/server/public/
COPY --from=builder /builder/server/package*.json /builder/server/.env* /xiaoju-survey/server/
COPY docker-run.sh /xiaoju-survey/docker-run.sh
# 覆盖nginx配置文件
COPY nginx/nginx.conf /etc/nginx/nginx.conf
2023-11-02 12:12:37 +00:00
# 暴露端口 需要跟nginx的port一致
2024-05-20 10:37:12 +00:00
EXPOSE 80
2023-11-02 12:12:37 +00:00
# docker入口文件,启动nginx和运行pm2启动,并保证监听不断
2023-11-02 12:12:37 +00:00
CMD ["sh","docker-run.sh"]