diff --git a/README.md b/README.md index e204a74..b1fe9a2 100644 --- a/README.md +++ b/README.md @@ -128,7 +128,8 @@ docker.createImage({fromImage: 'ubuntu'}, function (err, stream) { * `image` - container image * `cmd` - command to be executed * `stream` - stream(s) which will be used for execution output. -* `[create_options]` - options used for container creation. +* `create_options` - options used for container creation. (optional) +* `start_options` - options used for container start. (optional) * `callback` - callback called when execution ends. ``` js diff --git a/lib/docker.js b/lib/docker.js index 4d30b68..dc1bcf8 100644 --- a/lib/docker.js +++ b/lib/docker.js @@ -288,10 +288,14 @@ Docker.prototype.pull = function(repoTag, opts, callback) { return this.createImage.apply(this, args); }; -Docker.prototype.run = function(image, cmd, streamo, options, callback) { - if (!callback && typeof(options) === 'function') { - callback = options; - options = {}; +Docker.prototype.run = function(image, cmd, streamo, createOptions, startOptions, callback) { + if (!callback && typeof(createOptions) === 'function') { + callback = createOptions; + createOptions = {}; + startOptions = {}; + } else if (!callback && typeof(startOptions) === 'function') { + callback = startOptions; + startOptions = {}; } var hub = new EventEmitter(); @@ -319,7 +323,7 @@ Docker.prototype.run = function(image, cmd, streamo, options, callback) { } } - container.start(options, function(err, data) { + container.start(startOptions, function(err, data) { if(err) return callback(err, data); container.wait(function(err, data) { @@ -346,7 +350,7 @@ Docker.prototype.run = function(image, cmd, streamo, options, callback) { 'VolumesFrom': '' }; - _.extend(optsc, options); + _.extend(optsc, createOptions); this.createContainer(optsc, handler); diff --git a/package.json b/package.json index 298863d..e95b34a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "dockerode", "description": "Docker.io / Docker remote API implementation.", - "version": "2.0.2", + "version": "2.0.3", "author": "Pedro Dias ", "maintainers": [ "apocas " diff --git a/test/docker.js b/test/docker.js index c82dac2..736c822 100644 --- a/test/docker.js +++ b/test/docker.js @@ -187,21 +187,37 @@ describe("#docker", function() { docker.run('ubuntu', ['bash', '-c', 'uname -a'], process.stdout, handler); }); - it("should run a command with options", function(done){ + it("should run a command with start options", function(done){ function handler(err, data, container) { expect(err).to.be.null; - - container.inspect(function(err,data){ + + container.inspect(function(err, data){ expect(err).to.be.null; expect(data.HostConfig.Privileged).to.be.true; - container.remove(function(err,data){ + container.remove(function(err, data){ + expect(err).to.be.null; + done(); + }); + }); + } + docker.run('ubuntu', ['bash', '-c', 'uname -a'], process.stdout, {}, {Privileged : true}, handler); + }); + + it("should run a command with create options", function(done){ + function handler(err, data, container) { + expect(err).to.be.null; + + container.inspect(function(err, data){ + expect(err).to.be.null; + + container.remove(function(err, data){ expect(err).to.be.null; done(); }); }); } - docker.run('ubuntu', ['bash', '-c', 'uname -a'], process.stdout, {Privileged : true}, handler); + docker.run('ubuntu', ['bash', '-c', 'uname -a'], process.stdout, {}, handler); }); }); @@ -216,11 +232,11 @@ describe("#docker", function() { container.inspect(function (err, info) { expect(err).to.be.null; expect(info.Name).to.equal('/test'); - }); - container.remove(function(err, data) { - expect(err).to.be.null; - done(); + container.remove(function(err, data) { + expect(err).to.be.null; + done(); + }); }); }