2

Deploy nextjs app using docker and docker-compose

Virtualization and Containerization | by aayushchugh | submitted in October 20, 2024

Use this config to deploy nextjs applications using docker and docker-compose

# Dockerfile

FROM node:23-alpine

WORKDIR /app

COPY package*.json ./

RUN npm install 

COPY . /app

RUN npm run build

EXPOSE 3002

CMD ["npm", "start"]

# docker-compose.yml

services:
  <projectname>_nextjs:
    image: <projectname>
    container_name: <projectname>
    working_dir: /app
    ports:
      - "3000:3000"
    expose:
      - "3000"
    command: "npm start"
    environment:
      NODE_ENV: production
    env_file:
      - .env
    build:
      context: .
      dockerfile: Dockerfile

# Make sure to replace <projectname> with your project's name and ports with your preferred ports.