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.
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 EXPOSE 3000 # 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.