feat: configure Docker setup with multi-stage build for Next.js application

This commit is contained in:
Puechberty Arthur
2026-03-31 19:39:49 +02:00
parent c061960e57
commit 05bfb07286
2 changed files with 42 additions and 7 deletions
+34
View File
@@ -0,0 +1,34 @@
# === Étape 1 : Build ===
FROM node:20-alpine AS builder
WORKDIR /app
# Copier les fichiers de dépendances pour profiter du cache Docker
COPY package*.json ./
# Installer uniquement ce qu'il faut pour le build
RUN npm ci
# Copier tout le code
COPY . .
# Build Next.js pour la production
RUN npm run build
# === Étape 2 : Runner léger ===
FROM node:20-alpine AS runner
WORKDIR /app
# Copier uniquement ce qui est nécessaire pour la prod
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
# Mode production
ENV NODE_ENV=production
EXPOSE 3000
# Lancer le serveur Next.js
CMD ["npm", "start"]
+8 -7
View File
@@ -1,10 +1,11 @@
services:
clock-app:
image: node:21
working_dir: /app
web:
build: .
ports:
- "3000:3000"
volumes:
- ./:/app
command: sh -c "npm install && npm run build && npm start"
ports:
- "3007:3000"
restart: unless-stopped
- /app/node_modules
environment:
- NODE_ENV=development
command: npm run dev