I'm learning docker with nodejs. I tried to apply bind mount to update the webpage dynamically using NodeMon and -v
flag.
Changes were made in the server file in the container but no changes were observed on the webpage upon refreshing. So I'm guessing I didn't configure nodemon correctly?
This is my simple server code.
const express = require('express')
const app = express()
const port = 3088
app.get('/', (req, res) =>{
res.send("<h2>Hidasda</h2>")
})
app.listen(port, ()=>console.log(`${port}`))
This is my package.json
{
"name": "docker-practice",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js",
"dev": "nodemon -L index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.18.2"
},
"devDependencies": {
"nodemon": "^2.0.22"
}
}
This is a simple Dockerfile that I use.
FROM node:18
WORKDIR /app
COPY package.json /app/
RUN npm install
COPY . /app/
EXPOSE 3088
CMD [ "npm","run", "dev" ]
command to create docker container:
docker run -v $(pwd):/app -p 3088:3088 -d --name docker-practice-container docker-practice-image