0

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
zxcisnoias
  • 494
  • 3
  • 19
  • @about14sheep that seems more related to docker compose and as far as I can tell, OP is already doing everything required – Phil Apr 03 '23 at 00:49
  • One issue I see here is that you would also be mounting your host's `node_modules` directory which may contain modules built for your host architecture instead of the container's. You may want to add an anonymous volume mount to prevent that... `-v /app/node_modules` – Phil Apr 03 '23 at 00:52

0 Answers0