Added container listing function.

This commit is contained in:
Sean Li 2014-09-28 16:14:11 -07:00
parent 26132b0cdf
commit 32b14b5335
1 changed files with 27 additions and 0 deletions

View File

@ -27,6 +27,33 @@ Docker.removeContainer = function (containerId, callback) {
}); });
}; };
Docker.listContainers = function (callback) {
docker.listContainers(function (err, containers) {
if (err) {
callback(err, null);
} else {
var cbList = _.map(containers, function (container) {
return function (cb) {
Docker.getContainerData(container.Id, function (err, data) {
if (err) {
cb(err, null);
} else {
cb(null, data);
}
});
}
});
async.parallel(cbList, function (err, results) {
if (err) {
callback(err, null);
} else {
callback(null, results);
}
});
}
});
};
Docker.getContainerData = function (containerId, callback) { Docker.getContainerData = function (containerId, callback) {
var container = docker.getContainer(containerId); var container = docker.getContainer(containerId);
container.inspect(function (err, data) { container.inspect(function (err, data) {