diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b189a87 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +node_modules +.next +.git +.gitignore +README.md +.env*.local \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 0216da2..e9bc79d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,47 @@ -# Step 1: Build -FROM node:18-alpine AS builder +FROM node:18-alpine AS base +# Install dependencies only when needed +FROM base AS deps +RUN apk add --no-cache libc6-compat WORKDIR /app + +# Install dependencies +COPY package.json package-lock.json* ./ +RUN npm ci + +# Rebuild the source code only when needed +FROM base AS builder +WORKDIR /app +COPY --from=deps /app/node_modules ./node_modules COPY . . -RUN npm install + +# Build the application RUN npm run build -# Step 2: Run -FROM node:18-alpine - +# Production image, copy all the files and run next +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 ./.next -COPY --from=builder /app/node_modules ./node_modules -COPY --from=builder /app/package.json ./package.json -EXPOSE 3000 +# Set the correct permission for prerender cache +RUN mkdir .next +RUN chown nextjs:nodejs .next -CMD ["npm", "start"] +# Automatically leverage output traces to reduce image size +COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static + +USER nextjs + +EXPOSE 3005 + +ENV PORT 3005 +ENV HOSTNAME "0.0.0.0" + +CMD ["node", "server.js"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index a9a8565..5ce082a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,7 +8,7 @@ services: dockerfile: Dockerfile restart: always ports: - - "3000:3000" + - "3005:3005" networks: - coolify environment: diff --git a/next.config.ts b/next.config.ts index 681bcd0..634e140 100644 --- a/next.config.ts +++ b/next.config.ts @@ -2,6 +2,7 @@ import type { NextConfig } from "next"; const nextConfig: NextConfig = { /* config options here */ + output: "standalone", images: { remotePatterns: [ {