No matter what I'm trying, when containerizing my next.js website the site can't find files
Unanswered
Jindo posted this in #help-forum
JindoOP
Hey, so as the title suggests, I've tried DOZENS of different Dockerfile configurations and none made my website work
the website can't load public files (fonts/ images) nor the _static javascript files, I would like to get an insight
This is my dockerfile as of right now
is there anything I'm doing wrong at first glance?
This is my next.config.ts
the website can't load public files (fonts/ images) nor the _static javascript files, I would like to get an insight
This is my dockerfile as of right now
# syntax = docker/dockerfile:1
FROM node:22-slim AS base
ARG PORT=3000
ENV NEXT_TELEMETRY_DISABLED=1
WORKDIR /app
# Dependencies
FROM base AS dependencies
COPY package.json package-lock.json ./
RUN npm ci
# Build
FROM base AS builder
COPY --from=dependencies /app/node_modules ./node_modules
COPY . .
RUN npm run build
# Run
FROM base AS run
ENV NODE_ENV=production
ENV PORT=$PORT
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
RUN mkdir .next
RUN chown nextjs:nodejs .next
COPY --from=build /app/public ./public
COPY --from=build --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=build --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
EXPOSE $PORT
ENV HOSTNAME="0.0.0.0"
CMD ["node", "server.js"]
is there anything I'm doing wrong at first glance?
This is my next.config.ts
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
output: "standalone",
"experimental": {
"optimizePackageImports": ["@chakra-ui/react"]
},
images: {
localPatterns: [
{pathname: "/images/**", search: ""}
]
}
};
export default nextConfig;
1 Reply
JindoOP
bump