Dockerode: Running containers in a detached mode is difficult

Created on 28 Jul 2014  路  2Comments  路  Source: apocas/dockerode

Hi all, I'm using dockerode to manage my docker containers and its great so far, but the run command doesn't seem to be friendly to running containers in a detached mode. The implementation now always tries to attach to a container and then wait for it to be done before running the callback. I'd like to just call run and get a confirmation it is running. Would like to contribute, was wondering thoughts on a preferred way. My inclination is to add a new method, runDetached a la:

Docker.prototype.runDetached = function(image, cmd, options, callback) {
  if (!callback && typeof(options) === 'function') {
    callback = options;
    options = {};
  }
  function handler(err, container) {
    if (err) return callback(err, container);
    container.start(options, function(err, data) {
      if(err) return callback(err, data);
      callback(err, data, container);
    }); 
  }

  var optsc = {
    'Hostname': '',
    'User': '',
    'AttachStdin': false,
    'AttachStdout': false,
    'AttachStderr': false,
    'Tty': true,
    'OpenStdin': false,
    'StdinOnce': false,
    'Env': null,
    'Cmd': cmd,
    'Image': image,
    'Volumes': {},
    'VolumesFrom': ''
  };

  _.extend(optsc, options);

  this.createContainer(optsc, handler);
}

Thoughts? I'd be happy to submit a PR and include some tests, but don't want to go through the effort if you'd rather augment the run method. If that's the case, I'd rather not use the options object but don't have a better suggestion.

Thanks for the great lib!
Mike

Most helpful comment

I would argue that running detached is a highly used use case. It is the first section of the run reference after all (whether to run detached or not).

All 2 comments

Hi.

I highly advise you to implement your own run function on your side.
Dockerode's run is like Docker's run, it is impossible to support all use cases. :)

Each person as it's necessities, run can only support the most used ones. Can't implement N run functions and/or N options in each. :)

I would argue that running detached is a highly used use case. It is the first section of the run reference after all (whether to run detached or not).

Was this page helpful?
0 / 5 - 0 ratings