Docker Remote API driver for node.js. It uses the same modem than dockerode, but the interface is promisified and with a different syntax.
Support for:
- streams
- stream demux
- entities
- run
- tests
- promises
- full es6 support
The current status of the package is in beta state. This module covers the full API reference, including experimental stuff such as plugins.
Check the reference and the tests for full examples.
$ npm install node-docker-apiYou can find more into the examples folder
'use strict';const{Docker}=require('node-docker-api');constdocker=newDocker({socketPath: '/var/run/docker.sock'});docker.container.create({Image: 'ubuntu',name: 'test'}).then(container=>container.start()).then(container=>container.stop()).then(container=>container.restart()).then(container=>container.delete({force: true})).catch(error=>console.log(error));'use strict';const{Docker}=require('node-docker-api');constdocker=newDocker({socketPath: '/var/run/docker.sock'});// Listdocker.container.list()// Inspect.then(containers=>containers[0].status()).then(container=>container.top()).then(processes=>console.log(processes)).catch(error=>console.log(error));'use strict';const{Docker}=require('node-docker-api');constdocker=newDocker({socketPath: '/var/run/docker.sock'});// Listdocker.container.list()// Inspect.then(containers=>containers[0].status()).then(container=>container.stats()).then(stats=>{stats.on('data',stat=>console.log('Stats: ',stat.toString()))stats.on('error',err=>console.log('Error: ',err))}).catch(error=>console.log(error));'use strict';const{Docker}=require('node-docker-api');constdocker=newDocker({socketPath: '/var/run/docker.sock'});letcontainer;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))}).catch(error=>console.log(error));const{Docker}=require('node-docker-api');constfs=require('fs');constdocker=newDocker({socketPath: '/var/run/docker.sock'});letcontainer;docker.container.create({Image: 'ubuntu',name: 'test'}).then(container=>container.start()).then(container=>container.export()).then(content=>{constfile=fs.createWriteStream("container.tar");file.end(content)}).catch(error=>console.log(error));'use strict';constfs=require('fs');const{Docker}=require('node-docker-api');constpromisifyStream=stream=>newPromise((resolve,reject)=>{stream.on('data',data=>console.log(data.toString()))stream.on('end',resolve)stream.on('error',reject)});constdocker=newDocker({socketPath: '/var/run/docker.sock'});letcontainer;docker.container.create({Image: 'ubuntu',Cmd: ['/bin/bash','-c','tail -f /var/log/dmesg'],name: 'test'}).then(container=>container.start()).then(_container=>{container=_containerreturn_container.fs.put('./file.tar',{path: 'root'})}).then(stream=>promisifyStream(stream)).then(()=>container.fs.get({path: '/var/log/dmesg'})).then(stream=>{constfile=fs.createWriteStream("file.jpg");stream.pipe(file);returnpromisifyStream(stream);}).then(()=>container.status()).then(container=>container.stop()).catch(error=>console.log(error));'use strict';const{Docker}=require('node-docker-api');constpromisifyStream=stream=>newPromise((resolve,reject)=>{stream.on('data',data=>console.log(data.toString()))stream.on('end',resolve)stream.on('error',reject)});constdocker=newDocker({socketPath: '/var/run/docker.sock'});let_container;docker.container.create({Image: 'ubuntu',Cmd: ['/bin/bash','-c','tail -f /var/log/dmesg'],name: 'test'}).then(container=>container.start()).then(container=>{_container=containerreturncontainer.exec.create({AttachStdout: true,AttachStderr: true,Cmd: ['echo','test']})}).then(exec=>{returnexec.start({Detach: false})}).then(stream=>promisifyStream(stream)).then(()=>_container.kill()).catch(error=>console.log(error));'use strict';const{Docker}=require('node-docker-api');consttar=require('tar-fs');constpromisifyStream=stream=>newPromise((resolve,reject)=>{stream.on('data',data=>console.log(data.toString()))stream.on('end',resolve)stream.on('error',reject)});constdocker=newDocker({socketPath: '/var/run/docker.sock'});vartarStream=tar.pack('/path/to/Dockerfile')docker.image.build(tarStream,{t: 'testimg'}).then(stream=>promisifyStream(stream)).then(()=>docker.image.get('testimg').status()).then(image=>image.remove()).catch(error=>console.log(error));'use strict';const{Docker}=require('node-docker-api');constpromisifyStream=(stream)=>newPromise((resolve,reject)=>{stream.on('data',(d)=>console.log(d.toString()))stream.on('end',resolve)stream.on('error',reject)})constdocker=newDocker({socketPath: '/var/run/docker.sock'})returndocker.image.create({},{fromImage: 'ubuntu',tag: 'latest'}).then(stream=>promisifyStream(stream)).then(()=>docker.image.get('ubuntu').status()).then(image=>image.history()).then(events=>console.log(events)).catch(error=>console.log(error))'use strict'constfs=require('fs');const{Docker}=require('node-docker-api');constpromisifyStream=stream=>newPromise((resolve,reject)=>{stream.on('data',data=>console.log(data.toString()))stream.on('end',resolve)stream.on('error',reject)})constdocker=newDocker({socketPath: '/var/run/docker.sock'})docker.events({since: ((newDate().getTime()/1000)-60).toFixed(0)}).then(stream=>promisifyStream(stream)).catch(error=>console.log(error))