ker*_*erj 5 node.js node-supervisor docker nodemon fig
我正在使用Docker和fig来构建NodeJS dev-env.
当我使用nodemon来监视server.js时,更改server.js将不会重新启动服务器.
CMD ["nodemon", "/nodeapp/server.js"]
Run Code Online (Sandbox Code Playgroud)
但是当我从nodemon变为主管时,它就起作用了!
CMD ["supervisor", "/nodeapp/server.js"]
Run Code Online (Sandbox Code Playgroud)
有谁知道问题在哪里?
更多信息如下:
我的图文件夹结构:
app/server.js
package.json
node_modules/
fig.yml
Dockerfile
Run Code Online (Sandbox Code Playgroud)
fig.yml:
nodejs:
build: .
ports:
- "8080:8080"
Run Code Online (Sandbox Code Playgroud)
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"]
Run Code Online (Sandbox Code Playgroud)
Server.js :(来自NodeJS网站的示例代码)
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/');
Run Code Online (Sandbox Code Playgroud)
use special key for node moon:
nodemon --legacy-watch
Run Code Online (Sandbox Code Playgroud)
这就是我的做法:
为此,您将需要 nodemon 1.3.0-5 版 ( npm i -g nodemon@dev)
.dockerignore:
node_modules/*
Run Code Online (Sandbox Code Playgroud)
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"]
Run Code Online (Sandbox Code Playgroud)
包.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"
}
Run Code Online (Sandbox Code Playgroud)
图.yml:
nodejs:
build: .
command: node . --development
volumes:
- ./app:/nodeapp/app
ports:
- "8080:8080"
Run Code Online (Sandbox Code Playgroud)
应用程序/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/');
Run Code Online (Sandbox Code Playgroud)
然后我跑去npm run nodemon开始。
首先 -VOLUME ./app:/nodeapp没有执行您想要的操作 - 您正在图像中创建一个名为的目录/app:/nodeapp- 因此 server.js 文件绝不会进入您的图像。
测试使用docker run --rm -it yourimagename ls -la
将您的 Dockerfile 更改为
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"]
Run Code Online (Sandbox Code Playgroud)
让我:
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/
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10432 次 |
| 最近记录: |