Skip to content

Commit

Permalink
run with start options, v2.0.3 wrap
Browse files Browse the repository at this point in the history
  • Loading branch information
apocas committed Aug 20, 2014
1 parent f9e550e commit 2b3853c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 17 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 10 additions & 6 deletions lib/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand All @@ -346,7 +350,7 @@ Docker.prototype.run = function(image, cmd, streamo, options, callback) {
'VolumesFrom': ''
};

_.extend(optsc, options);
_.extend(optsc, createOptions);

this.createContainer(optsc, handler);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dockerode",
"description": "Docker.io / Docker remote API implementation.",
"version": "2.0.2",
"version": "2.0.3",
"author": "Pedro Dias <[email protected]>",
"maintainers": [
"apocas <[email protected]>"
Expand Down
34 changes: 25 additions & 9 deletions test/docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});

Expand All @@ -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();
});
});
}

Expand Down

0 comments on commit 2b3853c

Please sign in to comment.