Here is my project structure:
| Dockerfile | package-lock.json | package.json +---node_modules \---server index.js
First, I create a folder named "node-docker" in d:\ .
Then I execute the following command to initialize the folder.
npm init
Here is the Dockerfile content:
FROM node:alpine WORKDIR /app CMD ["npm","run","dev"] EXPOSE 80
The package.json content is as below:
{ "name": "node-docker", "version": "1.0.0", "description": "", "main": "index.js", "type": "module", "dependencies": { "express": "^4.18.2" }, "devDependencies": { "nodemon": "^2.0.20" }, "scripts": { "dev": "nodemon server/index.js", "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC" }
And the file server/index.js content is as follows:
import http from 'http';
import Express from 'express';
let app = new Express();
let httpServer = http.createServer(app);
let port = 80;
app.get('/', (req, res) => {
res.send('hello world')
});
httpServer.listen(port, () => {
console.log('Express server is running on localhost:' + port);
});
When I execute the npm run dev
command, when I update the string 'hello world' to 'hello world1', the browser shows the updated content when I refresh the browser, so the nodemon working properly.
I am using the following command to build a docker image:
D:\node-docker> docker build -t node-docker .
I am using the docker desktop to start the image container with the following optional setting.
Home path: d:\node-docker Container path:/app
The container is started properly. Unfortunately, when I update the string 'hello world' in server/index.js to 'hello world1', the browser does not show the latest content even I refresh the browser. Would you tell me how to fix the problem?
PS: I got the same result, when I perform the above steps on 2 individual computers.