-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathDockerfile
90 lines (62 loc) · 2.05 KB
/
Dockerfile
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# Build stage
FROM node:18-alpine AS builder
# Create non-root user
RUN addgroup -g 1001 appgroup && \
adduser -u 1001 -G appgroup -s /bin/sh -D appuser
WORKDIR /app
# Set ownership of the working directory
RUN chown -R appuser:appgroup /app
# Copy dependency files with correct ownership
COPY --chown=appuser:appgroup package*.json ./
# Create node_modules with correct permissions
RUN mkdir -p node_modules && chown -R appuser:appgroup node_modules
# Switch to non-root user
USER appuser
RUN npm install
# Copy source with correct ownership
COPY --chown=appuser:appgroup . .
RUN npm run build
# Production stage
FROM node:18-alpine AS production
# Create the same non-root user in production stage
RUN addgroup -g 1001 appgroup && \
adduser -u 1001 -G appgroup -s /bin/sh -D appuser
WORKDIR /app
# Set ownership of the working directory
RUN chown -R appuser:appgroup /app
ENV NODE_ENV production
ENV PORT 3000
ENV HOSTNAME "0.0.0.0"
# Copy dependency files with correct ownership
COPY --chown=appuser:appgroup package*.json ./
# Create node_modules with correct permissions
RUN mkdir -p node_modules && chown -R appuser:appgroup node_modules
# Switch to non-root user
USER appuser
RUN npm install --production
# Copy built files from builder stage with correct ownership
COPY --chown=appuser:appgroup --from=builder /app/.next ./.next
COPY --chown=appuser:appgroup --from=builder /app/public ./public
COPY --chown=appuser:appgroup --from=builder /app/next.config.js ./
EXPOSE 3000
CMD ["npm", "run", "start"]
# # Build stage
# FROM node:20-alpine
# WORKDIR /app
# # Update npm to latest version
# RUN npm install -g [email protected]
# # Copier uniquement les fichiers nécessaires pour npm install
# COPY package*.json ./
# COPY tsconfig*.json ./
# COPY next.config.js ./
# # Installer les dépendances avec cache
# RUN npm install
# # Set environment variables
# ENV NODE_ENV=development
# ENV NEXT_TELEMETRY_DISABLED=1
# ENV PORT=3000
# ENV HOSTNAME="0.0.0.0"
# # Exposer le port
# EXPOSE 3000
# # Utiliser npm run dev pour le hot reload
# CMD ["npm", "run", "dev"]