mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-22 16:43:35 +00:00
- 设置/app目录为775权限,解决sed临时文件创建问题 - 替换sed为awk进行文件内容修改,避免权限问题 - 使用/tmp目录作为临时文件存储位置 - 确保claude用户对所有必要目录和文件都有完整读写权限 - 彻底解决"couldn't open temporary file"和"permission denied"错误 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
65 lines
1.8 KiB
Docker
65 lines
1.8 KiB
Docker
# 🐳 使用官方 Node.js 18 Alpine 镜像
|
|
FROM node:18-alpine
|
|
|
|
# 📋 设置标签
|
|
LABEL maintainer="claude-relay-service@example.com"
|
|
LABEL description="Claude Code API Relay Service"
|
|
LABEL version="1.0.0"
|
|
|
|
# 🔧 安装系统依赖
|
|
RUN apk add --no-cache \
|
|
curl \
|
|
dumb-init \
|
|
sed \
|
|
&& rm -rf /var/cache/apk/*
|
|
|
|
# 👤 创建应用用户
|
|
RUN addgroup -g 1001 -S nodejs && \
|
|
adduser -S claude -u 1001 -G nodejs
|
|
|
|
# 📁 设置工作目录
|
|
WORKDIR /app
|
|
|
|
# 📦 复制 package 文件
|
|
COPY package*.json ./
|
|
|
|
# 🔽 安装依赖 (生产环境)
|
|
RUN npm ci --only=production && \
|
|
npm cache clean --force
|
|
|
|
# 📋 复制应用代码
|
|
COPY --chown=claude:nodejs . .
|
|
|
|
# 🔧 复制并设置启动脚本权限
|
|
COPY --chown=claude:nodejs docker-entrypoint.sh /usr/local/bin/
|
|
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
|
|
|
|
# 📁 创建必要目录并设置权限 - 一次性解决所有权限问题
|
|
RUN mkdir -p logs data temp && \
|
|
chown -R claude:nodejs /app && \
|
|
chmod 775 /app && \
|
|
chmod 775 /app/logs /app/data /app/temp /app/config
|
|
|
|
# 🔧 预先创建配置文件避免权限问题
|
|
RUN if [ ! -f "/app/config/config.js" ] && [ -f "/app/config/config.example.js" ]; then \
|
|
cp /app/config/config.example.js /app/config/config.js; \
|
|
fi && \
|
|
if [ ! -f "/app/.env" ] && [ -f "/app/.env.example" ]; then \
|
|
cp /app/.env.example /app/.env; \
|
|
fi && \
|
|
chown claude:nodejs /app/config/config.js /app/.env 2>/dev/null || true && \
|
|
chmod 664 /app/config/config.js /app/.env 2>/dev/null || true
|
|
|
|
# 🔐 切换到非 root 用户
|
|
USER claude
|
|
|
|
# 🌐 暴露端口
|
|
EXPOSE 3000
|
|
|
|
# 🏥 健康检查
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
|
CMD curl -f http://localhost:3000/health || exit 1
|
|
|
|
# 🚀 启动应用
|
|
ENTRYPOINT ["dumb-init", "--", "/usr/local/bin/docker-entrypoint.sh"]
|
|
CMD ["node", "src/app.js"] |