Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-docker-api

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-docker-api - npm Package Compare versions

Comparing version 1.0.12 to 1.1.0

2

package.json
{
"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",

@@ -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))
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc