Skip to content

Commit d20804f

Browse files
committed
1.0.2 docker images
1 parent c0ccaaa commit d20804f

4 files changed

Lines changed: 202 additions & 77 deletions

File tree

README.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,4 +168,87 @@ docker.command('ps').then(function (data) {
168168
// status: 'Up 33 minutes',
169169
// ports: '0.0.0.0:80->80/tcp, 443/tcp',
170170
// name: 'nginxcont' } ] }
171+
```
172+
173+
* docker images
174+
175+
```js
176+
177+
docker.command('images').then(function (data) {
178+
console.log('data = ', data);
179+
});
180+
181+
182+
data = { command: 'docker images ',
183+
// raw: '["REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE\\nquobjectio/consul
184+
// 0.5.2 c2e8640282e5 5 days ago 37.17 MB\\nquobjectio/consul 0.5.2c 74ae12b3b517 5 days ago 35.92 MB\\n<none> <none> 35682216ba6f 6 days ago
185+
//35.92 MB\\nquobjectio/mongodb 3.0.7 5ca1d18839fb 10 days ago 347 MB\\nquobjectio/mongodb
186+
//3.0.7d 5ca1d18839fb 10 days ago 347 MB\\nquobjectio/zookeeper 3.4.6-ubuntu-14.04 92eedb07b809 2 weeks ago 369.9 MB\\nswarm latest 6b40fe7724bd 2 weeks ago 15.6 MB\\nalpine 3.2 8a648f689ddb 9 weeks ago 5.249 MB\\nalpine latest 8a648f689ddb 9 weeks ago 5.249 MB\\nubuntu latest 91e54dfb1179
187+
//3 months ago 188.4 MB\\nubuntu 14.04 8251da35e7a7 3 months ago 188.4 MB\\nubuntu 15.04 23635bbeb7c5 3 months ago 131.3 MB\\ntutum/mongodb latest e27c5e60a8f1 5 months ago 502.6 MB\\n",""]',
188+
//images:
189+
//[ { repository: 'quobjectio/consul',
190+
// tag: '0.5.2',
191+
// 'image id': 'c2e8640282e5',
192+
// created: '5 days ago',
193+
// 'virtual size': '37.17 MB' },
194+
// { repository: 'quobjectio/consul',
195+
// tag: '0.5.2c',
196+
// 'image id': '74ae12b3b517',
197+
// created: '5 days ago',
198+
// 'virtual size': '35.92 MB' },
199+
// { repository: '<none>',
200+
// tag: '<none>',
201+
// 'image id': '35682216ba6f',
202+
// created: '6 days ago',
203+
// 'virtual size': '35.92 MB' },
204+
// { repository: 'quobjectio/mongodb',
205+
// tag: '3.0.7',
206+
// 'image id': '5ca1d18839fb',
207+
// created: '10 days ago',
208+
// 'virtual size': '347 MB' },
209+
// { repository: 'quobjectio/mongodb',
210+
// tag: '3.0.7d',
211+
// 'image id': '5ca1d18839fb',
212+
// created: '10 days ago',
213+
// 'virtual size': '347 MB' },
214+
// { repository: 'quobjectio/zookeeper',
215+
// tag: '3.4.6-ubuntu-14.04',
216+
// 'image id': '92eedb07b809',
217+
// created: '2 weeks ago',
218+
// 'virtual size': '369.9 MB' },
219+
// { repository: 'swarm',
220+
// tag: 'latest',
221+
// 'image id': '6b40fe7724bd',
222+
// created: '2 weeks ago',
223+
// 'virtual size': '15.6 MB' },
224+
// { repository: 'alpine',
225+
// tag: '3.2',
226+
// 'image id': '8a648f689ddb',
227+
// created: '9 weeks ago',
228+
// 'virtual size': '5.249 MB' },
229+
// { repository: 'alpine',
230+
// tag: 'latest',
231+
// 'image id': '8a648f689ddb',
232+
// created: '9 weeks ago',
233+
// 'virtual size': '5.249 MB' },
234+
// { repository: 'ubuntu',
235+
// tag: 'latest',
236+
// 'image id': '91e54dfb1179',
237+
// created: '3 months ago',
238+
// 'virtual size': '188.4 MB' },
239+
// { repository: 'ubuntu',
240+
// tag: '14.04',
241+
// 'image id': '8251da35e7a7',
242+
// created: '3 months ago',
243+
// 'virtual size': '188.4 MB' },
244+
// { repository: 'ubuntu',
245+
// tag: '15.04',
246+
// 'image id': '23635bbeb7c5',
247+
// created: '3 months ago',
248+
// 'virtual size': '131.3 MB' },
249+
// { repository: 'tutum/mongodb',
250+
// tag: 'latest',
251+
// 'image id': 'e27c5e60a8f1',
252+
// created: '5 months ago',
253+
// 'virtual size': '502.6 MB' } ] }
171254
```

lib/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ var exec = Promise.promisify(require('child_process').exec);
2020
var os = require("os");
2121
var _ = require('lodash');
2222
var dockermachine = require('dockermachineconfig');
23+
var cliTable2Json = require('cli-table-2-json');
2324

2425
var Docker = function (opts) {
2526
if (!(this instanceof Docker)) {
@@ -147,11 +148,25 @@ var extractResult = function (result) {
147148
// ports: '0.0.0.0:80->80/tcp, 443/tcp',
148149
// name: 'nginxcont' } ] }
149150

151+
return resultp;
152+
}
153+
},
154+
{
155+
re: / images /,
156+
run: function (resultp) {
157+
var obj = JSON.parse(resultp.raw);
158+
var lines = obj[0].split(os.EOL);
159+
160+
//var debug = require('debug')('docker-cli-js:lib/index.js extractResult images');
161+
//debug(lines);
162+
resultp.images = cliTable2Json(lines);
163+
150164
return resultp;
151165
}
152166
}
153167

154168

169+
155170
];
156171

157172
extracterArray.forEach(function (extracter) {

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "docker-cli-js",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "A wrapper for the docker CLI",
55
"main": "lib/index.js",
66
"scripts": {
@@ -32,6 +32,8 @@
3232
"dependencies": {
3333
"dockermachineconfig": "~1.0.4",
3434
"lodash": "~3.10.1",
35-
"bluebird": "~2.10.1"
35+
"bluebird": "~2.10.1",
36+
"debug": "~2.2.0",
37+
"cli-table-2-json": "~1.0.0"
3638
}
3739
}

test/index.js

Lines changed: 100 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -43,56 +43,56 @@ describe('docker', function () {
4343
// });
4444
//});
4545

46-
it('command info should pass', function (done) {
47-
var docker = new Docker({
48-
//machinename: config.DockerMachineName
49-
});
50-
//console.log('docker', docker);
51-
assert.isNotNull(docker);
52-
var failed = false;
53-
var err = null;
54-
docker.command('info').then(function (data) {
55-
//console.log('data = ', data);
56-
assert.isNotNull(data);
57-
//}).catch(function (error) {
58-
// assert.isNotNull(error);
59-
// err = error;
60-
// failed = true;
61-
// console.log('error = ', error);
62-
}).finally(function () {
63-
//console.log('finally ');
64-
assert.isFalse(failed);
65-
assert.isNull(err);
66-
done();
67-
});
68-
});
46+
//it('command info should pass', function (done) {
47+
// var docker = new Docker({
48+
// //machinename: config.DockerMachineName
49+
// });
50+
// //console.log('docker', docker);
51+
// assert.isNotNull(docker);
52+
// var failed = false;
53+
// var err = null;
54+
// docker.command('info').then(function (data) {
55+
// //console.log('data = ', data);
56+
// assert.isNotNull(data);
57+
// //}).catch(function (error) {
58+
// // assert.isNotNull(error);
59+
// // err = error;
60+
// // failed = true;
61+
// // console.log('error = ', error);
62+
// }).finally(function () {
63+
// //console.log('finally ');
64+
// assert.isFalse(failed);
65+
// assert.isNull(err);
66+
// done();
67+
// });
68+
//});
6969

7070

71-
it('command build should pass', function (done) {
72-
this.timeout(15000);
73-
var docker = new Docker({
74-
machinename: config.DockerMachineName,
75-
cwd: path.join(__dirname, 'nginx')
76-
});
77-
//console.log('docker', docker);
78-
assert.isNotNull(docker);
79-
var failed = false;
80-
var err = null;
81-
docker.command('build -t nginximg1 .').then(function (data) {
82-
//console.log('data = ', data);
83-
assert.isNotNull(data);
84-
}).catch(function (error) {
85-
assert.isNotNull(error);
86-
err = error;
87-
failed = true;
88-
//console.log('error = ', error);
89-
}).finally(function () {
90-
//console.log('finally ');
91-
assert.isFalse(failed);
92-
assert.isNull(err);
93-
done();
94-
});
95-
});
71+
//it('command build should pass', function (done) {
72+
// this.timeout(15000);
73+
// var docker = new Docker({
74+
// machinename: config.DockerMachineName,
75+
// cwd: path.join(__dirname, 'nginx')
76+
// });
77+
// //console.log('docker', docker);
78+
// assert.isNotNull(docker);
79+
// var failed = false;
80+
// var err = null;
81+
// docker.command('build -t nginximg1 .').then(function (data) {
82+
// //console.log('data = ', data);
83+
// assert.isNotNull(data);
84+
// }).catch(function (error) {
85+
// assert.isNotNull(error);
86+
// err = error;
87+
// failed = true;
88+
// //console.log('error = ', error);
89+
// }).finally(function () {
90+
// //console.log('finally ');
91+
// assert.isFalse(failed);
92+
// assert.isNull(err);
93+
// done();
94+
// });
95+
//});
9696

9797

9898
//it('command build with callback', function (done) {
@@ -110,32 +110,58 @@ describe('docker', function () {
110110
// });
111111
//});
112112

113-
it('command run', function (done) {
114-
this.timeout(15000);
115-
var docker = new Docker({
116-
machinename: config.DockerMachineName,
117-
});
118-
//console.log('docker', docker);
119-
assert.isNotNull(docker);
120-
var failed = false;
121-
var err = null;
122-
docker.command('run --name nginxcont -d -p 80:80 nginximg1').then(function (data) {
123-
console.log('data = ', data);
124-
assert.isNotNull(data);
125-
}).catch(function (error) {
126-
assert.isNotNull(error);
127-
err = error;
128-
failed = true;
129-
console.log('error = ', error);
130-
}).finally(function () {
131-
console.log('finally ');
132-
assert.isFalse(failed);
133-
assert.isNull(err);
134-
done();
135-
});
136-
});
113+
//it('command run', function (done) {
114+
// this.timeout(15000);
115+
// var docker = new Docker({
116+
// machinename: config.DockerMachineName,
117+
// });
118+
// //console.log('docker', docker);
119+
// assert.isNotNull(docker);
120+
// var failed = false;
121+
// var err = null;
122+
// docker.command('run --name nginxcont -d -p 80:80 nginximg1').then(function (data) {
123+
// console.log('data = ', data);
124+
// assert.isNotNull(data);
125+
// }).catch(function (error) {
126+
// assert.isNotNull(error);
127+
// err = error;
128+
// failed = true;
129+
// console.log('error = ', error);
130+
// }).finally(function () {
131+
// console.log('finally ');
132+
// assert.isFalse(failed);
133+
// assert.isNull(err);
134+
// done();
135+
// });
136+
//});
137+
138+
//it('command ps', function (done) {
139+
// this.timeout(15000);
140+
// var docker = new Docker({
141+
// //machinename: config.DockerMachineName,
142+
// });
143+
// //console.log('docker', docker);
144+
// assert.isNotNull(docker);
145+
// var failed = false;
146+
// var err = null;
147+
// docker.command('ps').then(function (data) {
148+
// console.log('data = ', data);
149+
// assert.isNotNull(data);
150+
// }).catch(function (error) {
151+
// assert.isNotNull(error);
152+
// err = error;
153+
// failed = true;
154+
// console.log('error = ', error);
155+
// }).finally(function () {
156+
// console.log('finally ');
157+
// assert.isFalse(failed);
158+
// assert.isNull(err);
159+
// done();
160+
// });
161+
//});
162+
137163

138-
it('command ps', function (done) {
164+
it('command images', function (done) {
139165
this.timeout(15000);
140166
var docker = new Docker({
141167
//machinename: config.DockerMachineName,
@@ -144,7 +170,7 @@ describe('docker', function () {
144170
assert.isNotNull(docker);
145171
var failed = false;
146172
var err = null;
147-
docker.command('ps').then(function (data) {
173+
docker.command('images').then(function (data) {
148174
console.log('data = ', data);
149175
assert.isNotNull(data);
150176
}).catch(function (error) {
@@ -160,7 +186,6 @@ describe('docker', function () {
160186
});
161187
});
162188

163-
164189
});
165190

166191

0 commit comments

Comments
 (0)