Nodemon not working in Docker environment

I am using Docker with fig to create NodeJS dev-env.

As long as I use nodemon to view server.js, changing server.js will not restart the server.

CMD ["nodemon", "/nodeapp/server.js"] 

But while I switched from nodemon to supervisor, then it will work!

 CMD ["supervisor", "/nodeapp/server.js"] 

Does anyone know where the problem is?

Further information below:


My folder structure:

 app/server.js package.json node_modules/ fig.yml Dockerfile 

fig.yml:

 nodejs: build: . ports: - "8080:8080" 

Dockerfile:

 RUN apt-get update --fix-missing RUN rm /bin/sh && ln -s /bin/bash /bin/sh # NVM RUN curl -sL https://deb.nodesource.com/setup | sudo bash - && \ apt-get install -y nodejs VOLUME ./app:/nodeapp WORKDIR /nodeapp RUN rm /bin/sh && ln -s /bin/bash /bin/sh && \ npm install -g nodemon mocha supervisor CMD ["nodemon", "/nodeapp/server.js"] 

Server.js: (sample code from NodeJS site)

 var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello 12\n'); }).listen(8080); console.log('Server running at http://127.0.0.1:8080/'); 
+5
source share
3 answers

first up - VOLUME ./app:/nodeapp does not do what you want - you create a directory on the image called /app:/nodeapp - and therefore, in no case does the server.js file get into your image.

using docker run --rm -it yourimagename ls -la

change the docker file to

 FROM ubuntu RUN apt-get update --fix-missing RUN apt-get install -yq curl RUN rm /bin/sh && ln -s /bin/bash /bin/sh # NVM RUN curl -sL https://deb.nodesource.com/setup | sudo bash - && \ apt-get install -y nodejs #VOLUME ./app:/nodeapp ADD app /nodeapp WORKDIR /nodeapp RUN rm /bin/sh && ln -s /bin/bash /bin/sh && \ npm install -g nodemon mocha supervisor CMD ["nodemon", "/nodeapp/server.js"] 

gets me:

 mini:nodaemon sven$ docker run --rm -it -p 8080:8080 nodaemon 2 Dec 02:27:52 - [nodemon] v1.2.1 2 Dec 02:27:52 - [nodemon] to restart at any time, enter `rs` 2 Dec 02:27:52 - [nodemon] watching: *.* 2 Dec 02:27:52 - [nodemon] starting `node /nodeapp/server.js` Server running at http://127.0.0.1:8080/ 
+1
source

Here is how I do it:

To do this, you will need nodemon version 1.3.0-5 ( npm i -g nodemon@dev )

.dockerignore:

 node_modules/* 

Dockerfile:

 FROM node:0.10 WORKDIR /nodeapp ADD ./package.json /nodeapp/package.json RUN npm install --production ADD ./app /nodeapp/app EXPOSE 8080 CMD ["node", ".", "--production"] 

package.json:

 { "name": "fig-nodemon", "version": "1.0.0", "description": "", "main": "./app/server.js", "scripts": { "nodemon": "fig up -d && fig run nodejs npm i --development && nodemon -x \"fig kill nodejs && fig build nodejs && fig start nodejs && fig logs nodejs\"" }, "author": "", "license": "MIT" } 

fig.yml:

 nodejs: build: . command: node . --development volumes: - ./app:/nodeapp/app ports: - "8080:8080" 

application / server.js:

 var http = require('http'); http.createServer(function (req, res) { res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Hello 13\n'); }).listen(8080); console.log('Server running at http://127.0.0.1:8080/'); 

then I ran npm run nodemon to get started.

+3
source

use a special key for the moon node:

 nodemon --legacy-watch 
0
source

Source: https://habr.com/ru/post/1208024/


All Articles