-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdockerfile
More file actions
58 lines (40 loc) · 1.35 KB
/
Copy pathdockerfile
File metadata and controls
58 lines (40 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# --- Builder stage ---
FROM node:18-alpine AS builder
WORKDIR /app
RUN apk add --no-cache \
python3 \
py3-pip \
make \
g++ \
&& ln -sf python3 /usr/bin/python
COPY package*.json ./
RUN npm ci
# Copy full source (including your real .env from host)
COPY . .
# ✅ Do NOT overwrite .env or regenerate APP_KEY
# Just ensure production settings are correct.
# Instead of sed, rely on .env or env vars at runtime.
RUN npm run build
# Copy .env into build (keeps your host-provided APP_KEY)
RUN cp .env ./build/.env
WORKDIR /app/build
RUN npm ci --omit=dev
# --- Final image ---
FROM node:18-alpine
WORKDIR /app/build
# Copy only the built app and production node_modules
COPY --from=builder /app/build /app/build
# Create non-root user for security
RUN addgroup -g 1001 -S nodejs && \
adduser -S nextjs -u 1001
# Create and set permissions for tmp directory
RUN mkdir -p /app/build/tmp && \
chown -R nextjs:nodejs /app/build/tmp
USER nextjs
EXPOSE 3333
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:3333/health || exit 1
# Create an entrypoint script to run migrations before starting the server
COPY --chown=nextjs:nodejs docker-entrypoint.sh /app/build/
RUN chmod +x /app/build/docker-entrypoint.sh
ENTRYPOINT ["/app/build/docker-entrypoint.sh"]