I'm using Docker with fig to build NodeJS dev-env.
While I using nodemon to watch the server.js, changing server.js won't restart the server.
CMD ["nodemon", "/nodeapp/server.js"]
But while I changed from nodemon to supervisor, then it worked!
CMD ["supervisor", "/nodeapp/server.js"]
Does anyone know where the problem is?
More informations are below:
My fig 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 website)
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/');
The following are some of the causes of the “Nodemon command not found” error. Nodemon is not installed. Nodemon is available in a different path. The Nodemon utility is not installed globally.
With a local installation, nodemon will not be available in your system path or you can't use it directly from the command line. Instead, the local installation of nodemon can be run by calling it from within an npm script (such as npm start ) or using npx nodemon .
There is a special option to enable nodemon's legacy watching mode:
nodemon --legacy-watch
This is how I do it:
You will need nodemon version 1.3.0-5 for this (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"
app/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 run npm run nodemon
to get started.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With