Not another Node.js Docker Remote API module.
dockerode
objectives:
- streams -
dockerode
does NOT break any stream, it passes them to you allowing for some stream voodoo. - stream demux - Supports optional stream demultiplexing.
- entities - containers, images and execs are defined entities and not random static methods.
- run -
dockerode
allow you to seamless run commands in a container aladocker run
. - tests -
dockerode
really aims to have a good test set, allowing to followDocker
changes easily, quickly and painlessly. - feature-rich - There's a real effort in keeping All
Docker
Remote API features implemented and tested. - interfaces - Features callback and promise based interfaces, making everyone happy :)
- docker-modem https://github.com/apocas/docker-modem - Docker's API network stack
- dockerode-compose https://github.com/apocas/dockerode-compose - docker-compose in Node.js
npm install dockerode
- Input options are directly passed to Docker. Check Docker API documentation for more details.
- Return values are unchanged from Docker, official Docker documentation will also apply to them.
- Check the tests and examples folder for more examples.
To use dockerode
first you need to instantiate it:
var Docker = require('dockerode');
var docker = new Docker({socketPath: '/var/run/docker.sock'});
var docker1 = new Docker(); //defaults to above if env variables are not used
var docker2 = new Docker({host: 'http://192.168.1.10', port: 3000});
var docker3 = new Docker({protocol:'http', host: '127.0.0.1', port: 3000});
var docker4 = new Docker({host: '127.0.0.1', port: 3000}); //defaults to http
//protocol http vs https is automatically detected
var docker5 = new Docker({
host: '192.168.1.10',
port: process.env.DOCKER_PORT || 2375,
ca: fs.readFileSync('ca.pem'),
cert: fs.readFileSync('cert.pem'),
key: fs.readFileSync('key.pem'),
version: 'v1.25' // required when Docker >= v1.13, https://docs.docker.com/engine/api/version-history/
});
var docker6 = new Docker({
protocol: 'https', //you can enforce a protocol
host: '192.168.1.10',
port: process.env.DOCKER_PORT || 2375,
ca: fs.readFileSync('ca.pem'),
cert: fs.readFileSync('cert.pem'),
key: fs.readFileSync('key.pem')
});
//using a different promise library (default is the native one)
var docker7 = new Docker({
Promise: require('bluebird')
//...
});
//...
// create a container entity. does not query API
var container = docker.getContainer('71501a8ab0f8');
// query API for container info
container.inspect(function (err, data) {
console.log(data);
});
container.start(function (err, data) {
console.log(data);
});
container.remove(function (err, data) {
console.log(data);
});
// promises are supported
var auxContainer;
docker.createContainer({
Image: 'ubuntu',
AttachStdin: false,
AttachStdout: true,
AttachStderr: true,
Tty: true,
Cmd: ['/bin/bash', '-c', 'tail -f /var/log/dmesg'],
OpenStdin: false,
StdinOnce: false
}).then(function(container) {
auxContainer = container;
return auxContainer.start();
}).then(function(data) {
return auxContainer.resize({
h: process.stdout.rows,
w: process.stdout.columns
});
}).then(function(data) {
return auxContainer.stop();
}).then(function(data) {
return auxContainer.remove();
}).then(function(data) {
console.log('container removed');
}).catch(function(err) {
console.log(err);
});