Dockership
Scriptable docker management tool build upon Docker remote API.
Usage
1. Get Start
var Dockership = require('dockership');
var dockerConfig = {
ca: 'path/to/ca',
cert: 'path/to/cert',
key: 'path/to/key',
host: '0.0.0.0',
port: 2376
};
var ship = new Dockership({
docker: dockerConfig,
buildContext: 'path/to/dockerfile/parent/dir',
meta: metaConfig
});
2. API
Dockership use dockerode and bluebird internally. All API calls will return a bluebird promise.
images method
Resolve with remote images specified by metaConfig.
ship.images().then(function (images) {
console.log(images);
});
containers method
ship.containers().then(function (containers) {
console.log(containers);
});
build method
ship.build().then(function (image) {
console.log(image);
});
ship instance is an EventEmitter instance. You can listen to events emitted during build process.
ship.on('buildMessage', function (obj) {
});
Dockership comes with logger helper to help log buildMessage to console.
var logger = Dockership.makeLogger();
ship.on('buildMessage', logger);
logger can be customized by passing a modifier function:
var logger = Dockership.makeLogger(function (str) {
return 'Prefix ' + str;
});
ship.on('buildMessage', logger);
start method
ship.start().then(function (container) {
console.log(container);
});
By default, start will start stopped container or create container from image specified in metaConfig. If such container or image cannot be found, start will reject.
stop method
Stop will stop all containers match the description in metaConfig.
ship.stop().then(function (containers) {
console.log(containers);
});
exec method
Execute command inside container. Reject if running container cannot be found.
ship.exec().then(function () {
});
this context
All promise callback have this refer to current ship instance.
ship
.build()
.then(function (image) {
return this.start();
})
.then(function (container) {
});
TODO
- Improve event emitting, especially error emitting.