Next.js Discord

Discord Forum

NextJs 404 errors on docker

Unanswered
Orinoco Crocodile posted this in #help-forum
Open in Discord
Orinoco CrocodileOP
On a docker standalone build all the JS files and css files are failing with 404 errors - Using the docker example from nextjs docs

37 Replies

Orinoco CrocodileOP
FROM node:18-alpine AS base

FROM base AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app

COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
RUN \
  if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
  elif [ -f package-lock.json ]; then npm ci; \
  elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
  else echo "Lockfile not found." && exit 1; \
  fi

FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

RUN yarn 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

RUN mkdir .next
RUN chown nextjs:nodejs .next

COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

EXPOSE 80

ENV PORT 80
ENV HOSTNAME "0.0.0.0"

CMD ["node", "server.js"]
also locally gives 404
Rough Collie
hmm your docker file looks alright
are you sure u structured your code right?
pages and components ^
Orinoco CrocodileOP
as far as I know...
It works in dev env
Rough Collie
what does your file tree look like?
Orinoco CrocodileOP
just not when built
Rough Collie
oh
did you lint your project before exporting/building?
Orinoco CrocodileOP
doesnt it do it as part of the build?
nothing in yarn lint
Rough Collie
yep but the build fail if there is any typing issues
Orinoco CrocodileOP
no type issues
Rough Collie
have you tried running the project out side of docker?
Orinoco CrocodileOP
yeah same issue (but unsure if need to change something)
Rough Collie
so its not an issue with docker
Orinoco CrocodileOP
yeah its an issue with standalone most likely
which is needed to deploy docker
Rough Collie
wait that docker configuration is for export use i think are u sure u grabbed the right docker config from the repo?
yep
yeah thats what I'm using
Rough Collie
unsure what’s going on
are mounting any other static files from another container?
or any sort of mounting that might remove/overwrite the generated files
Orinoco CrocodileOP
not that i'm aware of
gonna try docker build it locally
Rough Collie
what does your docker compose configuration look like?
Orinoco CrocodileOP
I'll need to ask the devops
Rough Collie
maybe it has something to do with the network interfacing
if your using something like nginx
Orinoco CrocodileOP
got it working!!
Rough Collie
What was the issue?
Orinoco CrocodileOP
I'm not sure exactly but something that the devops team found
With how it was built in our deploy chain