I’m at the beginning stages of learning to use docker as my development environment. I want to use NextJs and nodemon so I don’t have to keep restarting a container to see the changes.
My Dockerfile:
# syntax=docker/dockerfile:1
FROM node:18-alpine
WORKDIR /usr/src/app
COPY . .
RUN npm install --production
RUN npm run build
CMD ["npm", "start"]
My package.json:
{
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "latest",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
"devDependencies": {
"nodemon": "^2.0.20"
}
}
Shows to run the following:
docker run -dp 3000:3000 `
-w /app --mount type=bind,src="$(pwd)",target=/app `
node:18-alpine `
sh -c "yarn install && yarn run dev"
How do I configure this set up so I can make changes and see the changes straight away?
I’ve changed package.json
to
"scripts": {
"dev": "nodemon next dev",
"build": "next build",
"start": "next start"
},
Looking in the container logs I’m getting the following message:
2023-02-04 10:08:45 [nodemon] 2.0.20
2023-02-04 10:08:45 [nodemon] to restart at any time, enter `rs`
2023-02-04 10:08:45 [nodemon] watching path(s): *.*
2023-02-04 10:08:45 [nodemon] watching extensions: js,mjs,json
2023-02-04 10:08:45 [nodemon] starting `next start next dev`
2023-02-04 10:08:47 [nodemon] app crashed - waiting for file changes before starting...
2023-02-04 10:08:47 error - Invalid project directory provided, no such directory: /app/next
How do I correct the directory?