Search code examples
dockerinternationalizationnext.js

Next.js i18n routing not working in Docker


I'm trying to use the built-in Next.js internationalized routing.

I followed the steps and my code is more or less the same of the official example. Everything works fine both in local development environment and also with a production build environment.

My application in production runs inside a Docker swarm stack, so I build a Docker image with this dockerfile definition (I already have the Next.js build)

FROM mhart/alpine-node
WORKDIR /app
COPY ./.next /app/.next
COPY ./public /app/public
COPY ./node_modules /app/node_modules
COPY ./package.json /app/package.json
CMD ["npm", "run", "start"]

The command

npm run start

execute

next start

The app starts and works but when I change LANG next routing fails, it returns 404.

What am I missing?


Solution

  • You'll also need to copy your next.config.js file in the Dockerfile, that's where your i18n config is.

    COPY ./next.config.js /app/next.config.js