Automate Node Server with Docker and Gulp

Automate Node Server with Docker

To automate node server with using docker and gulp. first download the docker image for node server with following command

docker pull sfvishalgupta/imagenode:v0

Running the docker machine create the file with following code

# setup app server
echo 'Cleaning up previous docker images'
docker rm -f nodeContainer
service apache2 stop

DIR=$( cd `dirname $0`/..; pwd )

docker run -tid \
	--name nodeContainer \
	-p 80:3000 \
	-v ${DIR}/:/var/www/html \
	-v ${DIR}/bin/ \
	-w /var/www/html \
	sfvishalgupta/imagenode:v0 \

docker ps

with one file with following command

cd /var/www/html
gulp start

Now run

this will start the docker machine and bind its 3000 port to your port 80. and map the current directory to the /var/www/html dir which must have the node server code. So just open localhost or and you will be able to see the application.

To enter the docker machine run following command

docker exec -it suzukinode bash

Now create one gulpfile.js in code directory. with following task name start

'use strict';
var gulp = require('gulp'),
nodemon = require('gulp-nodemon');
gulp.task('start', function () {
        script: 'index.js',
	ext: 'js html',
	env: { 'NODE_ENV': 'development' }

Gulp is already in your docker machine. so as soon as we run the docker machine gulp start command with trigger via file. here nodemon will watch all js and html files if these extentions file got change nodemon will restart the server automatically and you can view changes in browser.

Leave a Reply

Your email address will not be published. Required fields are marked *