Skip to content

Commit 02193e7

Browse files
committed
feat: 添加 Dockerfile 和入口脚本,优化容器启动过程和权限管理
1 parent 4d30a8a commit 02193e7

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

Dockerfile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
FROM node:20-alpine
22

3+
RUN apk add --no-cache su-exec
4+
35
WORKDIR /app
46
ENV NODE_ENV=production
57

68
COPY package*.json ./
79
RUN npm ci --omit=dev
810

911
COPY . .
10-
RUN mkdir -p /app/public/images && chown -R node:node /app
11-
12-
USER node
12+
RUN mkdir -p /app/public/images && chown -R node:node /app \
13+
&& chmod +x /app/docker-entrypoint.sh
1314

1415
EXPOSE 3000
1516
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
1617
CMD wget -qO- http://localhost:3000/image/health || exit 1
18+
ENTRYPOINT ["/app/docker-entrypoint.sh"]
1719
CMD ["npm", "start"]

docker-entrypoint.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# Fix volume permissions: ensure node user can write to images directory
5+
if [ -d /app/public/images ]; then
6+
chown -R node:node /app/public/images 2>/dev/null || true
7+
fi
8+
9+
# Run the main process as node user
10+
exec su-exec node "$@"

0 commit comments

Comments
 (0)