React + Next.js with Docker

Following my previous post on Vuejs + Nuxt.js with Docker, I will show you how to dockerize a React + Next.js web application.

React is a JavaScript library for building user interfaces. Next.js is a framework for building React applications. Docker is a containerization platform that can be used to package and deploy these applications.

To dockerize a Next.js application, a Dockerfile is created that specifies the steps required to build the image.

FROM node:20-alpine

RUN mkdir -p /usr/src/app

# Set the working directory
WORKDIR /usr/src/app

COPY . .

RUN npm ci && npm cache clean --force
RUN npm run build


# Start the Next.js app
CMD ["npm", "start"]

Once the Dockerfile is created, the image can be built using the docker build command. The image can then be run using the docker run command.

You can now dockerize your Next.js app, if you want to learn about Let’s Encrypt check the previous post on Vuejs + Nuxt.js with Docker.

George Litos
George Litos
Senior Software Engineer