Installations
npm install node-docker-api
Score
87.1
Supply Chain
97.9
Quality
74.8
Maintenance
100
Vulnerability
80.6
License
Releases
Unable to fetch releases
Developer
AgustinCB
Developer Guide
Module System
CommonJS
Min. Node Version
Typescript Support
No
Node Version
NPM Version
Statistics
308 Stars
120 Commits
50 Forks
5 Watching
7 Branches
13 Contributors
Updated on 26 Nov 2024
Bundle Size
62.79 kB
Minified
14.50 kB
Minified + Gzipped
Languages
TypeScript (81.6%)
JavaScript (17.35%)
Shell (1.05%)
Total Downloads
Cumulative downloads
Total Downloads
5,289,372
Last day
-4.9%
7,273
Compared to previous day
Last week
4.5%
42,529
Compared to previous week
Last month
-13.7%
176,964
Compared to previous month
Last year
28.6%
2,014,048
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
2
docker-api
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.
Installation
1$ npm install node-docker-api
Usage
You can find more into the examples folder
Create, start, stop, restart and remove a container
1'use strict'; 2const {Docker} = require('node-docker-api'); 3 4const docker = new Docker({ socketPath: '/var/run/docker.sock' }); 5 6docker.container.create({ 7 Image: 'ubuntu', 8 name: 'test' 9}) 10 .then(container => container.start()) 11 .then(container => container.stop()) 12 .then(container => container.restart()) 13 .then(container => container.delete({ force: true })) 14 .catch(error => console.log(error));
List, inspect and top containers
1'use strict'; 2const {Docker} = require('node-docker-api'); 3 4const docker = new Docker({ socketPath: '/var/run/docker.sock' }); 5 6// List 7docker.container.list() 8 // Inspect 9 .then(containers => containers[0].status()) 10 .then(container => container.top()) 11 .then(processes => console.log(processes)) 12 .catch(error => console.log(error));
List, inspect and stat containers
1'use strict'; 2const {Docker} = require('node-docker-api'); 3 4const docker = new Docker({ socketPath: '/var/run/docker.sock' }); 5 6// List 7docker.container.list() 8 // Inspect 9 .then(containers => containers[0].status()) 10 .then(container => container.stats()) 11 .then(stats => { 12 stats.on('data', stat => console.log('Stats: ', stat.toString())) 13 stats.on('error', err => console.log('Error: ', err)) 14 }) 15 .catch(error => console.log(error));
Get logs of a container
1'use strict'; 2const {Docker} = require('node-docker-api'); 3 4const docker = new Docker({ socketPath: '/var/run/docker.sock' }); 5let container; 6 7docker.container.create({ 8 Image: 'ubuntu', 9 name: 'test' 10}) 11 .then(container => container.logs({ 12 follow: true, 13 stdout: true, 14 stderr: true 15 })) 16 .then(stream => { 17 stream.on('data', info => console.log(info)) 18 stream.on('error', err => console.log(err)) 19 }) 20 .catch(error => console.log(error));
Export a container
1const {Docker} = require('node-docker-api'); 2const fs = require('fs'); 3 4const docker = new Docker({ socketPath: '/var/run/docker.sock' }); 5let container; 6 7docker.container.create({ 8 Image: 'ubuntu', 9 name: 'test' 10}) 11 .then(container => container.start()) 12 .then(container => container.export()) 13 .then(content => { 14 const file = fs.createWriteStream("container.tar"); 15 file.end(content) 16 }) 17 .catch(error => console.log(error));
Manipulate file system in a container
1'use strict'; 2const fs = require('fs'); 3const {Docker} = require('node-docker-api'); 4 5const promisifyStream = stream => new Promise((resolve, reject) => { 6 stream.on('data', data => console.log(data.toString())) 7 stream.on('end', resolve) 8 stream.on('error', reject) 9}); 10 11const docker = new Docker({ socketPath: '/var/run/docker.sock' }); 12let container; 13 14docker.container.create({ 15 Image: 'ubuntu', 16 Cmd: [ '/bin/bash', '-c', 'tail -f /var/log/dmesg' ], 17 name: 'test' 18}) 19 .then(container => container.start()) 20 .then(_container => { 21 container = _container 22 return _container.fs.put('./file.tar', { 23 path: 'root' 24 }) 25 }) 26 .then(stream => promisifyStream(stream)) 27 .then(() => container.fs.get({ path: '/var/log/dmesg' })) 28 .then(stream => { 29 const file = fs.createWriteStream("file.jpg"); 30 stream.pipe(file); 31 return promisifyStream(stream); 32 }) 33 .then(() => container.status()) 34 .then(container => container.stop()) 35 .catch(error => console.log(error));
Execute commands and kill containers
1'use strict'; 2const {Docker} = require('node-docker-api'); 3 4const promisifyStream = stream => new Promise((resolve, reject) => { 5 stream.on('data', data => console.log(data.toString())) 6 stream.on('end', resolve) 7 stream.on('error', reject) 8}); 9 10const docker = new Docker({ socketPath: '/var/run/docker.sock' }); 11let _container; 12 13docker.container.create({ 14 Image: 'ubuntu', 15 Cmd: [ '/bin/bash', '-c', 'tail -f /var/log/dmesg' ], 16 name: 'test' 17}) 18 .then(container => container.start()) 19 .then(container => { 20 _container = container 21 return container.exec.create({ 22 AttachStdout: true, 23 AttachStderr: true, 24 Cmd: [ 'echo', 'test' ] 25 }) 26 }) 27 .then(exec => { 28 return exec.start({ Detach: false }) 29 }) 30 .then(stream => promisifyStream(stream)) 31 .then(() => _container.kill()) 32 .catch(error => console.log(error));
Build, inspect and remove an image
1'use strict'; 2const {Docker} = require('node-docker-api'); 3const tar = require('tar-fs'); 4 5const promisifyStream = stream => new Promise((resolve, reject) => { 6 stream.on('data', data => console.log(data.toString())) 7 stream.on('end', resolve) 8 stream.on('error', reject) 9}); 10 11const docker = new Docker({ socketPath: '/var/run/docker.sock' }); 12 13var tarStream = tar.pack('/path/to/Dockerfile') 14docker.image.build(tarStream, { 15 t: 'testimg' 16}) 17 .then(stream => promisifyStream(stream)) 18 .then(() => docker.image.get('testimg').status()) 19 .then(image => image.remove()) 20 .catch(error => console.log(error));
Pull and check history of an image
1'use strict'; 2const {Docker} = require('node-docker-api'); 3 4const promisifyStream = (stream) => new Promise((resolve, reject) => { 5 stream.on('data', (d) => console.log(d.toString())) 6 stream.on('end', resolve) 7 stream.on('error', reject) 8}) 9 10const docker = new Docker({ socketPath: '/var/run/docker.sock' }) 11 12return docker.image.create({}, { fromImage: 'ubuntu', tag: 'latest' }) 13 .then(stream => promisifyStream(stream)) 14 .then(() => docker.image.get('ubuntu').status()) 15 .then(image => image.history()) 16 .then(events => console.log(events)) 17 .catch(error => console.log(error))
Fetch events from docker
1'use strict' 2const fs = require('fs'); 3const {Docker} = require('node-docker-api'); 4 5const promisifyStream = stream => new Promise((resolve, reject) => { 6 stream.on('data', data => console.log(data.toString())) 7 stream.on('end', resolve) 8 stream.on('error', reject) 9}) 10 11const docker = new Docker({ socketPath: '/var/run/docker.sock' }) 12 13docker.events({ 14 since: ((new Date().getTime() / 1000) - 60).toFixed(0) 15}) 16 .then(stream => promisifyStream(stream)) 17 .catch(error => console.log(error))
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: GNU General Public License v3.0: LICENSE:0
Reason
Found 9/29 approved changesets -- score normalized to 3
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/AgustinCB/docker-api/npm.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/npm.yml:12: update your workflow using https://app.stepsecurity.io/secureworkflow/AgustinCB/docker-api/npm.yml/master?enable=pin
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 1 out of 1 npmCommand dependencies pinned
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/npm.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 12 are checked with a SAST tool
Reason
74 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-cwfw-4gq5-mrqx
- Warn: Project is vulnerable to: GHSA-g95f-p29q-9xw4
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-9vvw-cc9w-f27h
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-hr2v-3952-633q
- Warn: Project is vulnerable to: GHSA-h6ch-v84p-w6p9
- Warn: Project is vulnerable to: GHSA-ff7x-qrg7-qggm
- Warn: Project is vulnerable to: GHSA-qrmc-fj45-qfc2
- Warn: Project is vulnerable to: GHSA-74fj-2j2h-c42q
- Warn: Project is vulnerable to: GHSA-pw2r-vq6v-hr8c
- Warn: Project is vulnerable to: GHSA-jchw-25xp-jwwc
- Warn: Project is vulnerable to: GHSA-cxjh-pqwp-8mfp
- Warn: Project is vulnerable to: GHSA-8r6j-v8pm-fqw3
- Warn: Project is vulnerable to: MAL-2023-462
- Warn: Project is vulnerable to: GHSA-xf7w-r453-m56c
- Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97
- Warn: Project is vulnerable to: GHSA-qh2h-chj9-jffq
- Warn: Project is vulnerable to: GHSA-q42p-pg8m-cqh6
- Warn: Project is vulnerable to: GHSA-w457-6q6x-cgp9
- Warn: Project is vulnerable to: GHSA-62gr-4qp9-h98f
- Warn: Project is vulnerable to: GHSA-f52g-6jhx-586p
- Warn: Project is vulnerable to: GHSA-2cf5-4w76-r9qv
- Warn: Project is vulnerable to: GHSA-3cqr-58rm-57f8
- Warn: Project is vulnerable to: GHSA-g9r4-xpmj-mj65
- Warn: Project is vulnerable to: GHSA-q2c6-c6pm-g3gh
- Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44
- Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988
- Warn: Project is vulnerable to: GHSA-44pw-h2cw-w3vq
- Warn: Project is vulnerable to: GHSA-vfrc-7r7c-w9mx
- Warn: Project is vulnerable to: GHSA-7wwv-vh3v-89cq
- Warn: Project is vulnerable to: GHSA-jp4x-w63m-7wgm
- Warn: Project is vulnerable to: GHSA-c429-5p7v-vgjp
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37
- Warn: Project is vulnerable to: GHSA-p9w8-2mpq-49h9
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-fvqr-27wr-82fm
- Warn: Project is vulnerable to: GHSA-4xc9-xhrj-v574
- Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm
- Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-5v2h-r2cx-5xgj
- Warn: Project is vulnerable to: GHSA-rrrm-qjm4-v8hf
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-hxm2-r34f-qmc5
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m / GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-w9mr-4mfr-499f
- Warn: Project is vulnerable to: GHSA-w3w8-37jv-2c58
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-6g33-f262-xjp4
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-4rq4-32rv-6wp6
- Warn: Project is vulnerable to: GHSA-64g7-mvw6-v9qj
- Warn: Project is vulnerable to: GHSA-2m39-62fm-q8r3
- Warn: Project is vulnerable to: GHSA-mf6x-7mm4-x2g7
- Warn: Project is vulnerable to: GHSA-mxhp-79qh-mcx6
- Warn: Project is vulnerable to: GHSA-j44m-qm6p-hp7m
- Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9
- Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-g7q5-pjjr-gqvp
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-7p7h-4mm5-852v
- Warn: Project is vulnerable to: GHSA-332q-7ff2-57h2
- Warn: Project is vulnerable to: GHSA-cf4h-3jhx-xvhq
Score
3
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to node-docker-api
@redocly/cli
[@Redocly](https://redocly.com) CLI is your all-in-one OpenAPI utility. It builds, manages, improves, and quality-checks your OpenAPI descriptions, all of which comes in handy for various phases of the API Lifecycle. Create your own rulesets to make API g
@verdaccio/commons-api
Commons API utilities for Verdaccio
@types/docker-modem
TypeScript definitions for docker-modem
dockerode
Docker Remote API module.