From cd6378351eb01285b8a987874c3bb584dd62d269 Mon Sep 17 00:00:00 2001 From: fegger Date: Tue, 19 May 2026 19:37:42 +0200 Subject: [PATCH] Add Docker configuration for Next.js application --- Dockerfile | 33 +++++++++++++++++++++++++++++++++ docker-compose.yml | 33 +++++++++++++++++++++++++++++++++ next.config.mjs | 4 +++- 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 Dockerfile create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..17dc90d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +FROM node:20-alpine AS base + +FROM base AS deps +RUN apk add --no-cache libc6-compat +WORKDIR /app +COPY package.json package-lock.json* ./ +RUN npm ci + +FROM base AS builder +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules +COPY . . +RUN npx prisma generate +RUN npm run build + +FROM base AS runner +WORKDIR /app +ENV NODE_ENV production + +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs + +COPY --from=builder /app/public ./public +COPY --from=builder /app/.next/standalone ./ +COPY --from=builder /app/.next/static ./.next/static +COPY --from=builder /app/prisma ./prisma + +USER nextjs + +EXPOSE 3000 +ENV PORT=3000 + +CMD ["node", "server.js"] diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..83c386d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,33 @@ +services: + app: + build: + context: . + dockerfile: Dockerfile + ports: + - "3000:3000" + environment: + DATABASE_URL: postgresql://bikeapp:bikeapp@db:5432/bikeapp + JWT_SECRET: ${JWT_SECRET:-your-super-secret-jwt-key-change-in-production} + depends_on: + db: + condition: service_healthy + restart: unless-stopped + + db: + image: postgres:16-alpine + environment: + POSTGRES_USER: bikeapp + POSTGRES_PASSWORD: bikeapp + POSTGRES_DB: bikeapp + volumes: + - postgres_data:/var/lib/postgresql/data + ports: + - "5432:5432" + healthcheck: + test: ["CMD-SHELL", "pg_isready -U bikeapp -d bikeapp"] + interval: 5s + timeout: 5s + retries: 5 + +volumes: + postgres_data: diff --git a/next.config.mjs b/next.config.mjs index 4678774..608f1be 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -1,4 +1,6 @@ /** @type {import('next').NextConfig} */ -const nextConfig = {}; +const nextConfig = { + output: "standalone", +}; export default nextConfig;