lib/container.js
function(tag, confImage, callback) {

      grunt.log.subhead(actioning[action] + ' image [' + tag + ']');

      async.waterfall([

      // Step 1: search for a running container with the same image
      function(cb) {
        docker.listContainers({
          all : 1,
        // filters: (action !== 'unpause') ? '{"status":["running"]}' : null
        }, function(err, containers) {

          if (err) {
            return cb(err);
          }

          var container = null;

          for (var c = 0; c < containers.length; c++) {
            if (containers[c].Image.indexOf(utils.qualifiedImageName(tag,
                  options.registry, null)) === 0) {
              container = containers[c];
              break;
            }
          }

          cb(null, container);
        });
      },

      // Step 2: stop it
      function(container, cb) {
        if (container) {
          grunt.log.writeln("Found a matched container, " + action + " it.");

          var dockcontainer = docker.getContainer(container.Id);

          var opts = confImage.options && confImage.options[action] || {};
          dockcontainer[action](opts, function(e, stream) {
            if (stream && stream.readable) {
              stream.setEncoding('utf8');
              stream.on('error', cb);
              stream.on('end', cb);
              stream.on('data', grunt.log.write);
            } else {
              cb(e);
            }

          });
        } else {
          grunt.log.writeln("No matched container with this image.");
          cb(null);
        }
      }, ], callback);

    }
function(tag, confImage, callback) {

      grunt.log.subhead(actioning[action] + ' image [' + tag + ']');

      async.waterfall([

      // Step 1: search for a running container with the same image
      function(cb) {
        docker.listContainers({
          all : 1,
        // filters: (action !== 'unpause') ? '{"status":["running"]}' : null
        }, function(err, containers) {

          if (err) {
            return cb(err);
          }

          var container = null;

          for (var c = 0; c < containers.length; c++) {
            if (containers[c].Image.indexOf(utils.qualifiedImageName(tag,
                  options.registry, null)) === 0) {
              container = containers[c];
              break;
            }
          }

          cb(null, container);
        });
      },

      // Step 2: stop it
      function(container, cb) {
        if (container) {
          grunt.log.writeln("Found a matched container, " + action + " it.");

          var dockcontainer = docker.getContainer(container.Id);

          var opts = confImage.options && confImage.options[action] || {};
          dockcontainer[action](opts, function(e, stream) {
            if (stream && stream.readable) {
              stream.setEncoding('utf8');
              stream.on('error', cb);
              stream.on('end', cb);
              stream.on('data', grunt.log.write);
            } else {
              cb(e);
            }

          });
        } else {
          grunt.log.writeln("No matched container with this image.");
          cb(null);
        }
      }, ], callback);

    }
function ( tag , confImage , callback ) { grunt . log . subhead ( actioning [ action ] + ' image [' + tag + ']' ) ; async . waterfall ( [ // Step 1: search for a running container with the same image function ( cb ) { docker . listContainers ( { all : 1 , // filters: (action !== 'unpause') ? '{"status":["running"]}' : null } , function ( err , containers ) { if ( err ) { return cb ( err ) ; } var container = null ; for ( var c = 0 ; c < containers . length ; c ++ ) { if ( containers [ c ] . Image . indexOf ( utils . qualifiedImageName ( tag , options . registry , null ) ) === 0 ) { container = containers [ c ] ; break ; } } cb ( null , container ) ; } ) ; } , // Step 2: stop it function ( container , cb ) { if ( container ) { grunt . log . writeln ( "Found a matched container, " + action + " it." ) ; var dockcontainer = docker . getContainer ( container . Id ) ; var opts = confImage . options && confImage . options [ action ] || { } ; dockcontainer [ action ] ( opts , function ( e , stream ) { if ( stream && stream . readable ) { stream . setEncoding ( 'utf8' ) ; stream . on ( 'error' , cb ) ; stream . on ( 'end' , cb ) ; stream . on ( 'data' , grunt . log . write ) ; } else { cb ( e ) ; } } ) ; } else { grunt . log . writeln ( "No matched container with this image." ) ; cb ( null ) ; } } , ] , callback ) ; }
process 1 container with image tag
process 1 container with image tag