Refactor Docker configuration for development and production environments

This commit is contained in:
Puechberty Arthur
2026-03-31 22:54:43 +02:00
parent 63e6c64077
commit f714ab4fcb
2 changed files with 42 additions and 24 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 -24
View File
@@ -1,27 +1,11 @@
services: services:
blocnote: web:
image: node:22-alpine build: .
container_name: blocnote
working_dir: /app
volumes:
- .:/app
- node_modules:/app/node_modules
- nextjs_cache:/app/.next
ports: ports:
- "3016:3000" - "3000:3000"
volumes:
- ./:/app
- /app/node_modules
environment: environment:
- NODE_ENV=production - NODE_ENV=development
- NEXT_TELEMETRY_DISABLED=1 command: npm run dev
- HOSTNAME=0.0.0.0
command: sh -c "npm ci --include=dev && npm run build && npm start"
restart: unless-stopped
healthcheck:
test: ["CMD", "wget", "-q", "--spider", "http://localhost:3000"]
interval: 30s
timeout: 10s
retries: 3
start_period: 60s
volumes:
node_modules:
nextjs_cache: