2017-01-06 39 views
0

我想整天找到一些解決方案,如何運行在docker中並行編寫的兩個腳本。docker>使用gulp和nodemon運行兩個nodejs腳本

我有兩個文件: - 使用端口8080 應用程序/ rabbit.js快遞應用 - 應用程序/ index.js腳本連接僅作爲消費者和處理信息的RabbitMQ

我試圖使用杯和nodemon(我發現在計算器的解決方案,但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']); 

這是始終運行第二個腳本「應用程序/ rabbit.js」兩次。我對任何解決方案都是開放的,但我需要在一個docker實例中一次運行兩個nodejs腳本。

任何想法? 在此先感謝!

回答

0

對於任何有同樣問題的人,我找到了解決方案。

步驟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