docker-cli-js
A node.js wrapper for the docker command line tool
![NPM](https://nodei.co/npm-dl/docker-cli-js.png?months=6&height=3)
![NPM downloads](https://img.shields.io/npm/dm/docker-cli-js.svg?style=flat)
Installation
Step 1: Prerequisites
The docker command line tool must be installed and accessible in the path
Step 2: Installation
npm install docker-cli-js
Then:
var dockerCLI = require('docker-cli-js');
var DockerOptions = dockerCLI.Options;
var Docker = dockerCLI.Docker;
Usage
With promise
var options = new DockerOptions(
'aws_machine01',
'nginx'
);
var docker = new Docker(options);
docker.command('build -t nginximg .').then(function (data) {
console.log('data = ', data);
})
With callback:
var docker = new Docker();
docker.command('info', function (err, data) {
console.log('data = ', data);
});
Typescript
import { Docker, Options } from 'docker-cli-js';
const options = new Options(
null,
path.join(__dirname, '..', 'test', 'nginx')
);
let docker = new Docker(options);
docker.command('build -t nginximg .').then(function (data) {
console.log('data = ', data);
});
docker.command('run --name nginxcont -d -p 80:80 nginximg').then(function (data) {
console.log('data = ', data);
});
docker.command('ps').then(function (data) {
console.log('data = ', data);
});
docker.command('images').then(function (data) {
console.log('data = ', data);
});
docker.command('network ls').then(function (data) {
console.log('data = ', data);
});
docker.command('inspect consul').then(function (data) {
console.log('data = ', data);
});
docker.command('info').then(function (data) {
console.log('data = ', data);
});
docker.command('search nginxcont').then(function (data) {
console.log('data = ', data);
});
docker.command('login -u myusername -p mypassword').then(function (data) {
console.log('data = ', data);
}, function (rejected) {
console.log('rejected = ', rejected);
});
License
MIT