Skip to content

Commit f45af15

Browse files
committed
v2.0.2
1 parent 5fa19b4 commit f45af15

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

examples/timeout.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
var Docker = require('../lib/docker');
2+
var fs = require('fs');
3+
4+
var socket = process.env.DOCKER_SOCKET || '/var/run/docker.sock';
5+
var stats = fs.statSync(socket);
6+
7+
if (!stats.isSocket()) {
8+
throw new Error("Are you sure the docker is running?");
9+
}
10+
11+
//you may specify a timeout for all operations, allowing to make sure you don't fall into limbo if something happens in docker
12+
var docker = new Docker({host: 'http://127.0.0.1', port: 2375, timeout: 1});
13+
14+
docker.createContainer({Image: 'ubuntu', Cmd: ['/bin/bash']}, function (err, container) {
15+
container.start(function (err, data) {
16+
container.top({ps_args: 'aux'}, function(err, data) {
17+
console.log(data);
18+
});
19+
});
20+
});

package.json

Lines changed: 1 addition & 1 deletion
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": "2.0.1",
4+
"version": "2.0.2",
55
"author": "Pedro Dias <petermdias@gmail.com>",
66
"maintainers": [
77
"apocas <petermdias@gmail.com>"

test/docker.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,19 @@ describe("#docker", function() {
8181
});
8282
});
8383

84+
describe("#testTimeout", function() {
85+
it("should timeout", function(done) {
86+
this.timeout(30000);
87+
88+
function handler(err, data) {
89+
expect(err).to.not.be.null;
90+
done();
91+
}
92+
93+
dockert.ping(handler);
94+
});
95+
});
96+
8497
describe('#pull', function() {
8598
this.timeout(120000);
8699

test/spec_helper.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ var docker;
1313
if (!stats.isSocket()) {
1414
console.log('Trying TCP connection...');
1515
docker = new Docker({host: process.env.DOCKER_HOST || 'http://127.0.0.1', port: process.env.DOCKER_PORT || 3000});
16+
dockert = new Docker({host: process.env.DOCKER_HOST || 'http://127.0.0.1', port: process.env.DOCKER_PORT || 3000, timeout: 1});
1617
} else {
1718
docker = new Docker({ socketPath: socket });
19+
dockert = new Docker({ socketPath: socket, timeout: 1 });
1820
}
1921

2022
module.exports = {
21-
'docker': docker
23+
'docker': docker,
24+
'dockert': dockert
2225
};

0 commit comments

Comments
 (0)