node-docker-api
Advanced tools
Comparing version 1.0.12 to 1.1.0
{ | ||
"name": "node-docker-api", | ||
"version": "1.0.12", | ||
"version": "1.1.0", | ||
"description": "Docker Remote API driver for node", | ||
@@ -5,0 +5,0 @@ "main": "./lib/docker", |
187
README.md
@@ -18,3 +18,3 @@ # docker-api | ||
Check the [reference](https://github.com/AgustinCB/docker-api/tree/master/docs). | ||
Check the [reference](https://github.com/AgustinCB/docker-api/tree/master/docs) and the [tests](https://github.com/AgustinCB/docker-api/tree/master/test) for full examples. | ||
@@ -27,3 +27,3 @@ ## Installation | ||
Check tests for a more general usage. | ||
### Create, start, stop, restart and remove a container | ||
@@ -40,6 +40,187 @@ ``` js | ||
.then((container) => container.start()) | ||
.then((container) => container.fs.put('file.txt'), { | ||
.then((container) => container.stop()) | ||
.then((container) => container.restart()) | ||
.then((container) => container.remove({ force: true })) | ||
``` | ||
### List, inspect and top containers | ||
``` js | ||
const Docker = require('node-docker-api').Docker | ||
let docker = new Docker({ socketPath: '/var/run/docker.sock' }) | ||
// List | ||
docker.container.list() | ||
// Inspect | ||
.then((containers) => containers[0].status()) | ||
.then((container) => container.top()) | ||
.then((processes) => console.log(processes)) | ||
``` | ||
### List, inspect and stat containers | ||
``` js | ||
const Docker = require('node-docker-api').Docker | ||
let docker = new Docker({ socketPath: '/var/run/docker.sock' }) | ||
// List | ||
docker.container.list() | ||
// Inspect | ||
.then((containers) => containers[0].status()) | ||
.then((container) => container.stats()) | ||
.then((stats) => { | ||
stats.on('data', (stat) => console.log('Stats: ',stat)) | ||
stats.on('error', (err) => console.log('Error: ', err)) | ||
}) | ||
``` | ||
### Get logs of a container | ||
```js | ||
const Docker = require('node-docker-api').Docker | ||
let docker = new Docker({ socketPath: '/var/run/docker.sock' }) | ||
let container | ||
docker.container.create({ | ||
Image: 'ubuntu', | ||
name: 'test' | ||
}) | ||
.then((container) => container.logs({ | ||
follow: true, | ||
stdout: true, | ||
stderr: true | ||
})) | ||
.then((stream) => { | ||
stream.on('data', (info) => console.log(info)) | ||
stream.on('error', (err) => console.log(err)) | ||
}) | ||
``` | ||
### Export a container | ||
``` js | ||
const Docker = require('node-docker-api').Docker, | ||
fs = require('fs') | ||
let docker = new Docker({ socketPath: '/var/run/docker.sock' }) | ||
let container | ||
docker.container.create({ | ||
Image: 'ubuntu', | ||
name: 'test' | ||
}) | ||
.then((container) => container.start()) | ||
.then((container) => container.export()) | ||
.then((stream) => { | ||
let file = fs.createWriteStream("container.tar"); | ||
stream.pipe(file) | ||
}) | ||
``` | ||
### Manipulate file system in a container | ||
``` js | ||
const Docker = require('node-docker-api').Docker, | ||
fs = require('fs') | ||
const promisifyStream = (stream) => new Promise((resolve, reject) => { | ||
stream.on('end', resolve) | ||
stream.on('error', reject) | ||
}) | ||
let docker = new Docker({ socketPath: '/var/run/docker.sock' }) | ||
docker.container.create({ | ||
Image: 'ubuntu', | ||
name: 'test' | ||
}) | ||
.then((container) => container.start()) | ||
.then((container) => container.fs.put('file.txt', { | ||
path: '/root' | ||
})) | ||
.then((stream) => promisifyStream(stream)) | ||
.then(() => container.fs.get('/root/file.txt')) | ||
.then((stream) => { | ||
let file = fs.createWriteStream("file.jpg"); | ||
stream.pipe(file) | ||
return promisifyStream(stream) | ||
}) | ||
.then(() => docker.container.status({ id: 'test' })) | ||
.then((container) => container.stop()) | ||
``` | ||
### Execute commands and kill containers | ||
``` js | ||
const Docker = require('node-docker-api').Docker | ||
let docker = new Docker({ socketPath: '/var/run/docker.sock' }) | ||
docker.container.create({ | ||
Image: 'ubuntu', | ||
name: 'test' | ||
}) | ||
.then((container) => container.start()) | ||
.then((_container) => { | ||
container = _container | ||
return container.exec.create({ | ||
Cmd: [ "top" ] | ||
}) | ||
}) | ||
.then((stream) => promisifyStream(stream)) | ||
.then((exec) => { | ||
return exec.start() | ||
}) | ||
.then((stream) => { | ||
stream.on('data', (info) => { | ||
console.log(info) | ||
_container.kill() | ||
}) | ||
stream.on('error', (err) => console.log(err)) | ||
}) | ||
``` | ||
### Build, inspect and remove an image | ||
``` js | ||
const Docker = require('node-docker-api').Docker, | ||
tar = require('tar-fs') | ||
const promisifyStream = (stream) => new Promise((resolve, reject) => { | ||
stream.on('end', resolve) | ||
stream.on('error', reject) | ||
}) | ||
let docker = new Docker({ socketPath: '/var/run/docker.sock' }) | ||
var tarStream = tar.pack('/path/to/Dockerfile') | ||
docker.image.build(tarStream, { | ||
'testimg' | ||
}) | ||
.then((stream) => promisifyStream(stream)) | ||
.then(() => docker.image.status('testimg')) | ||
.then((image) => image.remove()) | ||
``` | ||
### Pull and check history of an image | ||
``` js | ||
const Docker = require('node-docker-api').Docker | ||
const promisifyStream = (stream) => new Promise((resolve, reject) => { | ||
stream.on('end', resolve) | ||
stream.on('error', reject) | ||
}) | ||
let docker = new Docker({ socketPath: '/var/run/docker.sock' }) | ||
return docker.image.create({ fromImage: 'ubuntu' }) | ||
.then((stream) => promisifyStream(stream)) | ||
.then(() => docker.image.status('ubuntu')) | ||
.then((image) => image.history()) | ||
.then((events) => console.log(events)) | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
306581
224