While using anonymous volume and bind mount, I’m unable to use nodemon correctly inside the docker container. When I checked the file changes inside the container, I can see those changes seems like nodemon is unable to pickup those changes.
server.ts:-
app.get('/', (req, res) => {
console.log('Testing this GET API..');
res.status(201).send('Hello from Docker and Kubernetes');
});
package.json:-
{
"name": "rest-api-endpoints-for-todo-project",
"version": "1.0.0",
"description": "",
"main": "server.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1",
"build": "tsc",
"start": "nodemon --legacy-watch --watch ./src/server.ts --exec npm run build"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"jsonwebtoken": "^9.0.2",
"lodash": "^4.17.21",
"md5": "^2.3.0",
"mssql": "^6.2.1",
"typescript": "^5.3.3"
},
"devDependencies": {
"@types/cors": "^2.8.17",
"@types/express": "^4.17.21",
"@types/jsonwebtoken": "^9.0.2",
"@types/mssql": "^9.1.4",
"@types/node": "^20.11.15",
"concurrently": "^8.2.2",
"nodemon": "^3.1.2",
"ts-node": "^10.9.2"
}
}
Dockerfile:-
FROM node:21
WORKDIR /app
COPY ./package.json .
RUN npm install
COPY . .
EXPOSE 4000
CMD ["npm","start"]
After building the project, dist folder is generated which keeps the server.js file within it at dist/src/server.js.
Tried to check the logs of the container, but not getting the changes after making any code change inside the server.ts file. But getting the change after building it. And also I checked the code inside the container filesystem, it’s reflecting properly. So, I’m expecting nodemon to be the culprit.