docker > 运行 使用 gulp 和 nodemon 的两个 nodejs 脚本
docker > run two nodejs scripts using gulp and nodemon
我整天都在努力寻找一些解决方案,如何 运行 在 docker 中并行使用 nodejs 编写的两个脚本。
我有两个文件:
app/index.js - 使用端口 8080 的快速应用
app/rabbit.js - 脚本仅作为消费者和处理消息连接到 rabbitmq
我正在尝试使用 gulp 和 nodemon(我在 Whosebug 上找到了解决方案,但 id 不起作用)
var gulp = require('gulp')
var gulputil = require('gulp-util');
var child_process = require('child_process');
var nodemon = require('gulp-nodemon');
var processes = {server1: null, server2: null};
gulp.task('start:server', function (cb) {
processes.server1 = nodemon({
script: "app/index.js",
ext: "js"
});
processes.server2 = nodemon({
script: "app/rabbit.js",
ext: "js"
});
cb(); // For parallel execution accept a callback.
// For further info see "Async task support" section here:
// https://github.com/gulpjs/gulp/blob/master/docs/API.md
});
process.on('exit', function () {
// In case the gulp process is closed (e.g. by pressing [CTRL + C]) stop both processes
processes.server1.kill();
processes.server2.kill();
});
gulp.task('run', ['start:server']);
gulp.task('default', ['run']);
这总是 运行 的第二个脚本 "app/rabbit.js" 两次。我对任何解决方案持开放态度,但我需要在一个 docker 个实例中同时 运行 两个 nodejs 脚本。
有什么想法吗?
提前致谢!
对于遇到同样问题的任何人,我已经找到了解决方案。
第 1 步:
Create two docker files Dockerfile-api, Dockerfile-messages
As command RUN in the dockerfile use
a. CMD ["npm", "run", "start-api"]
b. CMD ["npm", "run", "start-messages"]
第 2 步:
In the package.json add lines:
"scripts": {
"start-api": "gulp --gulpfile app/gulpfile-api.js",
"start-messages": "gulp --gulpfile app/gulpfile-messages.js"
}
第 3 步:
Obviously create two gulp files, each gulp file will have his own script.
第 4 步:
Create two services in docker-compose.yml file each witch different DockerFile
第 5 步:
Run docker-compose up
我整天都在努力寻找一些解决方案,如何 运行 在 docker 中并行使用 nodejs 编写的两个脚本。
我有两个文件: app/index.js - 使用端口 8080 的快速应用 app/rabbit.js - 脚本仅作为消费者和处理消息连接到 rabbitmq
我正在尝试使用 gulp 和 nodemon(我在 Whosebug 上找到了解决方案,但 id 不起作用)
var gulp = require('gulp')
var gulputil = require('gulp-util');
var child_process = require('child_process');
var nodemon = require('gulp-nodemon');
var processes = {server1: null, server2: null};
gulp.task('start:server', function (cb) {
processes.server1 = nodemon({
script: "app/index.js",
ext: "js"
});
processes.server2 = nodemon({
script: "app/rabbit.js",
ext: "js"
});
cb(); // For parallel execution accept a callback.
// For further info see "Async task support" section here:
// https://github.com/gulpjs/gulp/blob/master/docs/API.md
});
process.on('exit', function () {
// In case the gulp process is closed (e.g. by pressing [CTRL + C]) stop both processes
processes.server1.kill();
processes.server2.kill();
});
gulp.task('run', ['start:server']);
gulp.task('default', ['run']);
这总是 运行 的第二个脚本 "app/rabbit.js" 两次。我对任何解决方案持开放态度,但我需要在一个 docker 个实例中同时 运行 两个 nodejs 脚本。
有什么想法吗? 提前致谢!
对于遇到同样问题的任何人,我已经找到了解决方案。
第 1 步:
Create two docker files Dockerfile-api, Dockerfile-messages
As command RUN in the dockerfile use
a. CMD ["npm", "run", "start-api"]
b. CMD ["npm", "run", "start-messages"]
第 2 步:
In the package.json add lines:
"scripts": {
"start-api": "gulp --gulpfile app/gulpfile-api.js",
"start-messages": "gulp --gulpfile app/gulpfile-messages.js"
}
第 3 步:
Obviously create two gulp files, each gulp file will have his own script.
第 4 步:
Create two services in docker-compose.yml file each witch different DockerFile
第 5 步:
Run docker-compose up