Skip to content

Commit 4a01c58

Browse files
committed
v1.3.0
1 parent 230a00a commit 4a01c58

File tree

5 files changed

+155
-39
lines changed

5 files changed

+155
-39
lines changed

README.md

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Not another Node.js Docker.io Remote API module.
77
Why `dockerode` is different from other Docker node.js modules:
88

99
* **streams** - `dockerode` does NOT break any stream, it passes them to you allowing for some stream voodoo.
10-
* **stream demux** - Supports optional demultiplexing of the new attach stream system implemented in Remote API v1.6.
10+
* **stream demux** - Supports optional demultiplexing of the new attach stream system implemented in Remote API v1.6.
1111
* **entities** - containers and images are defined entities and not random static methods.
1212
* **run** - `dockerode` allow you to seamless run commands in a container ala `docker run`.
1313
* **tests** - `dockerode` really aims to have a good test set, allowing to follow `Docker` changes easily, quickly and painlessly.
@@ -20,7 +20,7 @@ Why `dockerode` is different from other Docker node.js modules:
2020

2121
## Usage
2222

23-
* Input options are directly passed to Docker.io. Check [Docker Remote API documentation](http://docs.docker.io/en/latest/api/docker_remote_api/) for more details.
23+
* Input options are directly passed to Docker.io. Check [Docker Remote API documentation](http://docs.docker.io/reference/api/docker_remote_api/) for more details.
2424
* Return values are unchanged from Docker, official Docker.io documentation will also apply to them.
2525
* Check the tests for more examples.
2626

@@ -51,11 +51,17 @@ container.remove(function (err, data) {
5151
//...
5252
```
5353

54+
You may also specify default options for each container's operations, which will always be used for the specified container and operation.
55+
56+
``` js
57+
container.defaultOptions.start.Binds = ["/tmp:/tmp:rw"];
58+
```
59+
5460
### Stopping all containers on a host
5561

5662
``` js
57-
docker.listContainers(function(err, containers) {
58-
containers.forEach(function(containerInfo) {
63+
docker.listContainers(function (err, containers) {
64+
containers.forEach(function (containerInfo) {
5965
docker.getContainer(containerInfo.Id).stop(cb);
6066
});
6167
});
@@ -64,16 +70,16 @@ docker.listContainers(function(err, containers) {
6470
### Building an Image
6571

6672
``` js
67-
docker.buildImage('archive.tar', {t: imageName}, function(err, response){
73+
docker.buildImage('archive.tar', {t: imageName}, function (err, response){
6874
//...
6975
});
7076
```
7177

7278
### Creating a container:
7379

7480
``` js
75-
docker.createContainer({Image: 'ubuntu', Cmd: ['/bin/bash']}, function(err, container) {
76-
container.start(function(err, data) {
81+
docker.createContainer({Image: 'ubuntu', Cmd: ['/bin/bash']}, function (err, container) {
82+
container.start(function (err, data) {
7783
//...
7884
});
7985
});
@@ -84,18 +90,17 @@ docker.createContainer({Image: 'ubuntu', Cmd: ['/bin/bash']}, function(err, cont
8490

8591
``` js
8692
//tty:true
87-
container.attach({stream: true, stdout: true, stderr: true, tty: true}, function(err, stream) {
93+
container.attach({stream: true, stdout: true, stderr: true, tty: true}, function (err, stream) {
8894
stream.pipe(process.stdout);
8995
});
9096

9197
//tty:false
92-
container.attach({stream: true, stdout: true, stderr: true, tty: false}, function(err, stream) {
93-
//http://docs.docker.io/en/latest/api/docker_remote_api_v1.7/#post--containers-(id)-attach
94-
//dockerode may demultiplex the streams for you :)
98+
container.attach({stream: true, stdout: true, stderr: true, tty: false}, function (err, stream) {
99+
//dockerode may demultiplex attach streams for you :)
95100
container.modem.demuxStream(stream, process.stdout, process.stderr);
96101
});
97102

98-
docker.createImage({fromImage: 'ubuntu'}, function(err, stream) {
103+
docker.createImage({fromImage: 'ubuntu'}, function (err, stream) {
99104
stream.pipe(process.stdout);
100105
});
101106

@@ -107,33 +112,43 @@ docker.createImage({fromImage: 'ubuntu'}, function(err, stream) {
107112
* `image` - container image
108113
* `cmd` - command to be executed
109114
* `stream` - stream(s) which will be used for execution output.
115+
* `[create_options]` - options used for container creation.
110116
* `callback` - callback called when execution ends.
111117

112118
``` js
113-
docker.run('ubuntu', ['bash', '-c', 'uname -a'], process.stdout, function(err, data, container) {
119+
docker.run('ubuntu', ['bash', '-c', 'uname -a'], process.stdout, function (err, data, container) {
114120
console.log(data.StatusCode);
115121
});
116122
```
117123

118124
or, if you want to split stdout and stderr (you must to pass `Tty:false` as an option for this to work)
119125

120126
``` js
121-
docker.run('ubuntu', ['bash', '-c', 'uname -a'], [process.stdout, process.stderr], {Tty:false}, function(err, data, container) {
127+
docker.run('ubuntu', ['bash', '-c', 'uname -a'], [process.stdout, process.stderr], {Tty:false}, function (err, data, container) {
122128
console.log(data.StatusCode);
123129
});
124130
```
125131

132+
Run also returns an EventEmitter supporting the following events: container, stream, data. Allowing stuff like this:
133+
134+
``` js
135+
docker.run('ubuntu', ['bash', '-c', 'uname -a'], [process.stdout, process.stderr], {Tty:false}, function (err, data, container) {
136+
//...
137+
}).on('container', function (container) {
138+
container.defaultOptions.start.Binds = ["/tmp:/tmp:rw"];
139+
});
140+
```
141+
126142
### Equivalent of `docker pull` in `dockerode`:
127143

128144
* `repoTag` - container image name (optionally with tag)
129145
`myrepo/myname:withtag`
130-
* `opts` - extra options passed to create image see [docker api](http://docs.docker.io/en/latest/api/docker_remote_api_v1.8/#create-an-image)
146+
* `opts` - extra options passed to create image.
131147
* `callback` - callback called when execution ends.
132148

133149
``` js
134-
docker.pull('myrepo/myname:tag', function(err, stream) {
135-
// streaming output from pull...
136-
// Also see: http://docs.docker.io/en/latest/api/docker_remote_api_v1.8/#create-an-image
150+
docker.pull('myrepo/myname:tag', function (err, stream) {
151+
// streaming output from pull...
137152
});
138153
```
139154

lib/docker.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Docker.prototype.buildImage = function(file, opts, callback) {
7878
callback = opts;
7979
opts = null;
8080
}
81-
81+
8282
var self = this;
8383
var opts = {
8484
path: '/build?',
@@ -247,19 +247,19 @@ Docker.prototype.run = function(image, cmd, streamo, options, callback) {
247247
callback = options;
248248
options = {};
249249
}
250-
250+
251251
var hub = new EventEmitter();
252252

253253
function handler(err, container) {
254254
if (err) return callback(err, container);
255-
255+
256256
hub.emit('container', container);
257257

258258
container.attach({stream: true, stdout: true, stderr: true}, function handler(err, stream) {
259259
if (err) return callback(err, data);
260260

261-
hub.emit('stream', stream);
262-
261+
hub.emit('stream', stream);
262+
263263
if (streamo) {
264264
if (streamo instanceof Array) {
265265
container.modem.demuxStream(stream, streamo[0], streamo[1]);
@@ -299,7 +299,7 @@ Docker.prototype.run = function(image, cmd, streamo, options, callback) {
299299
_.extend(optsc, options);
300300

301301
this.createContainer(optsc, handler);
302-
302+
303303
return hub;
304304
};
305305

package.json

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "dockerode",
33
"description": "Docker.io / Docker remote API implementation.",
4-
"version": "1.2.10",
4+
"version": "1.3.0",
55
"author": "Pedro Dias <petermdias@gmail.com>",
66
"maintainers": [
77
"apocas <petermdias@gmail.com>"
@@ -29,5 +29,95 @@
2929
},
3030
"engines": {
3131
"node": ">= 0.8"
32-
}
32+
},
33+
"contributors": [
34+
{
35+
"name": "Pedro Dias",
36+
"email": "petermdias@gmail.com",
37+
"url": "https://github.com/apocas",
38+
"contributions": 93
39+
},
40+
{
41+
"name": "James Lal",
42+
"email": "jlal@mozilla.com",
43+
"url": "https://github.com/lightsofapollo",
44+
"contributions": 12
45+
},
46+
{
47+
"name": "Everton Ribeiro",
48+
"email": "nuxlli@gmail.com",
49+
"url": "https://github.com/nuxlli",
50+
"contributions": 4
51+
},
52+
{
53+
"name": "Sam Rijs",
54+
"email": "srijs@airpost.net",
55+
"url": "https://github.com/srijs",
56+
"contributions": 3
57+
},
58+
{
59+
"name": "Mike MacCana",
60+
"email": "mike.maccana@gmail.com",
61+
"url": "https://github.com/mikemaccana",
62+
"contributions": 2
63+
},
64+
{
65+
"url": "https://github.com/niclashoyer",
66+
"contributions": 2
67+
},
68+
{
69+
"name": "Alex Wolfe",
70+
"email": "alexkwolfe@gmail.com",
71+
"url": "https://github.com/alexkwolfe",
72+
"contributions": 1
73+
},
74+
{
75+
"name": "Vincent Woo",
76+
"email": "me@vincentwoo.com",
77+
"url": "https://github.com/vincentwoo",
78+
"contributions": 1
79+
},
80+
{
81+
"name": "Adam Duncan",
82+
"email": "",
83+
"url": "https://github.com/microadam",
84+
"contributions": 1
85+
},
86+
{
87+
"name": "Geoffrey Bachelet",
88+
"email": "geoffrey.bachelet@gmail.com",
89+
"url": "https://github.com/ubermuda",
90+
"contributions": 1
91+
},
92+
{
93+
"name": "Josh Matthews",
94+
"email": "josh@jmatthews.us",
95+
"url": "https://github.com/jmatth",
96+
"contributions": 1
97+
},
98+
{
99+
"name": "Kishore Nallan",
100+
"email": "kishore@kishorelive.com",
101+
"url": "https://github.com/kishorenc",
102+
"contributions": 1
103+
},
104+
{
105+
"name": "Mathias Buus",
106+
"email": "mathiasbuus@gmail.com",
107+
"url": "https://github.com/mafintosh",
108+
"contributions": 1
109+
},
110+
{
111+
"name": "Shannon Poole",
112+
"email": "shannon.m.poole@gmail.com",
113+
"url": "https://github.com/shannonmpoole",
114+
"contributions": 1
115+
},
116+
{
117+
"name": "Dan Williams",
118+
"email": "me+github@deedubs.com",
119+
"url": "https://github.com/deedubs",
120+
"contributions": 1
121+
}
122+
]
33123
}

test/docker.js

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ describe("#docker", function() {
7272
this.timeout(120000);
7373

7474
// one image with one tag
75-
var repoTag = 'lightsofapollo/test-taskenv:fail';
75+
var repoTag = 'ubuntu:latest';
7676

7777
// XXX: Should this be an extra abstraction in docker.js?
7878
function locateImage(image, callback) {
@@ -121,18 +121,29 @@ describe("#docker", function() {
121121

122122
describe("#run", function() {
123123
this.timeout(30000);
124-
it('should report malformed request errors', function(done) {
125-
function handler(err, data) {
126-
expect(err).to.be.ok;
127-
done();
124+
125+
it("should emit partial data", function(done) {
126+
function handler(err, data, container) {
127+
expect(err).to.be.null;
128+
//container is created
129+
expect(container).to.be.ok;
130+
131+
container.remove(function(err, data) {
132+
expect(err).to.be.null;
133+
});
128134
}
129135

130-
docker.run(
131-
'ubuntu',
132-
'exit 1', // this is an invalid parameter type (it should be an array)
133-
process.stdout,
134-
handler
135-
);
136+
var ee = docker.run('ubuntu', ['bash', '-c', 'uname -a'], process.stdout, handler);
137+
ee.on('container', function (container) {
138+
expect(container).to.be.ok;
139+
});
140+
ee.on('stream', function (stream) {
141+
expect(stream).to.be.ok;
142+
});
143+
ee.on('data', function (data) {
144+
expect(data).to.be.ok;
145+
done();
146+
});
136147
});
137148

138149
it("should run a command", function(done) {
@@ -161,8 +172,8 @@ describe("#docker", function() {
161172

162173
container.inspect(function (err, info) {
163174
expect(err).to.be.null;
164-
expect(info.Name).to.equal('/test')
165-
})
175+
expect(info.Name).to.equal('/test');
176+
});
166177

167178
container.remove(function(err, data) {
168179
expect(err).to.be.null;

test/test.tar

4 KB
Binary file not shown.

0 commit comments

Comments
 (0)