All Blogs

NextJS to Dockerize using Docker Compose

chat

Go to your folder and run

docker init

set the details accordingly

docker init

Go to Dockerfile and set it

FROM node
WORKDIR /src/app

COPY package*.json ./

# Run the application as a non-root user.
RUN npm install

# Copy the rest of the source files into the image.
COPY . .

# Expose the port that the application listens on.
EXPOSE 3000

# Run the application.
CMD npm run dev

Go to compose.yaml and set it

version: "3.9"
services:
  frontend:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - 3000:3000
    develop:
      watch:
        - path: ./package.json
          action: rebuild
        - path: ./package-lock.json
          action: rebuild
        - path: ./next.config.mjs
          action: rebuild
        - path: .
          target: /src/app
          action: sync
          
volumes:
  tasked:


Then run for winows

docker compose up

Then run for linux

sudo docker compose up

For realtime update Run

sudo docker compose watch
Lets

Chat

©2026

pritamdev2k@gmail.com