dailiip/Dockerfile

51 lines
1.2 KiB
Docker
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 使用官方Node.js运行时作为基础镜像
FROM node:24.11.0-alpine
# 设置工作目录
WORKDIR /app
# 设置环境变量
ENV NODE_ENV=production
ENV PORT=3000
# 配置国内镜像源
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
# 安装系统依赖(使用国内镜像源)
RUN apk add --no-cache \
sqlite \
sqlite-dev \
python3 \
make \
g++
# 配置npm使用国内镜像源
# RUN npm config set registry https://registry.npmmirror.com
# 复制package.json和package-lock.json如果存在
COPY package*.json ./
# 安装项目依赖
#RUN npm config set proyx http://192.168.3.135:1084
RUN npm config set https-proxy http://192.168.3.135:1084
RUN npm install
# 复制项目文件
COPY . .
# 创建数据目录和日志目录并设置权限
RUN mkdir -p /app/data /app/logs
# chown -R node:node /app
# 切换到非root用户
# USER node
# 暴露端口
EXPOSE 3000
# 健康检查
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD node -e "require('http').get('http://localhost:3000/api/health', (res) => { process.exit(res.statusCode === 200 ? 0 : 1) })"
# 启动应用
CMD ["npm", "start"]