assetPrefix not applied correctly when using Docker
Unanswered
Bombay-duck posted this in #help-forum
Bombay-duckOP
Hi!
this is my first help post..
im not good at english sorry🥲
So,
I'm using Next.js version
When I run
all files, including CSS and JS, are correctly loaded with the assetPrefix from env that
However, when I build the project using
Here’s some context
Does anyone know why
Thanks in advance!
Thankyou....!
this is my first help post..
im not good at english sorry🥲
So,
I'm using Next.js version
14.2.16When I run
yarn build:loc and yarn start:loc locally on my machine, everything works fine.all files, including CSS and JS, are correctly loaded with the assetPrefix from env that
NEXT_PUBLIC_STATIC_HOSTHowever, when I build the project using
Docker and run it, some files (like CSS and some JS chunks) are not loaded with the correct assetPrefix. I’m not sure why this is happening.Here’s some context
// next.config.js
const nextConfigWithBundleAnalyzer = withBundleAnalyzer({
reactStrictMode: false,
generateBuildId: () => nextBuildId({ dir: __dirname }),
assetPrefix: process.env.NEXT_PUBLIC_STATIC_HOST,
compress: true,
// ...
});// .env.loc
NEXT_PUBLIC_STATIC_HOST=<my cdn url here>
// package.json scripts
"scripts": {
"build:loc": "env-cmd -f .env.loc next build",
"start:loc": "env-cmd -f .env.loc next start"
}# Dockerfile (simplified)
FROM node:18-alpine AS base
FROM base AS builder
WORKDIR /app
COPY package.json yarn.lock build.sh ./
ENV ACTION="yarn install --frozen-lockfile"
RUN sh build.sh
COPY . .
ENV ACTION="yarn build:loc"
RUN sh build.sh
FROM base AS runner
WORKDIR /app
COPY --from=builder /app/node_modules /app/node_modules
COPY --from=builder /app/.next /app/.next
COPY --from=builder /app/public /app/public
COPY --from=deps /app/package.json /app/package.json
COPY --from=deps /app/.env.loc /app/.env.loc
EXPOSE 3000
CMD yarn start:loc# build.sh
$ACTIONDoes anyone know why
assetPrefix might not be applied properly in the Docker environment even though it works locally?Thanks in advance!
Thankyou....!
1 Reply
Bombay-duckOP
Here’s a screenshot for reference — hope it helps clarify the issue