How to deploy Next.js 9.5 with Dockerfile on Traefik

Hi,

I am getting bad gateway or 404 page not found error. How can I serve Next.js as a Docker image on Traefik v2.2.8?

Dockerfile

FROM node:12.18.3-alpine3.12

COPY . /app
WORKDIR /app

RUN npm install

RUN npm run build

EXPOSE 3000

CMD [ "npm", "run", "start" ]

.dockerignore

.next/
node_modules/
.git
.gitignore
Dockerfile

Server port is 80 on Traefik's docker-compose.yml
- "traefik.http.services.simple-nextjs.loadbalancer.server.port=80"

This solution worked for me.

Dockerfile

FROM node:12

ENV PORT 3000

# Create app directory
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

# Installing dependencies
COPY package*.json /usr/src/app/
RUN npm install

# Copying source files
COPY . /usr/src/app

# Building app
RUN npm run build
EXPOSE 3000

# Running the app
CMD "npm" "run" "start"

Change port to 3000
- "traefik.http.services.simple-nextjs.loadbalancer.server.port=3000"