Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running containers in a detached mode is difficult #77

Closed
mmacaula opened this issue Jul 28, 2014 · 2 comments
Closed

Running containers in a detached mode is difficult #77

mmacaula opened this issue Jul 28, 2014 · 2 comments

Comments

@mmacaula
Copy link
Contributor

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

@apocas
Copy link
Owner

apocas commented Jul 28, 2014

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. :)

@apocas apocas closed this as completed Jul 28, 2014
@mmacaula
Copy link
Contributor Author

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants