{"id":13534103,"url":"https://github.com/AgustinCB/docker-api","last_synced_at":"2025-04-01T22:31:14.910Z","repository":{"id":37884900,"uuid":"62671670","full_name":"AgustinCB/docker-api","owner":"AgustinCB","description":"Docker Remote API driver for node.js. It uses the same modem than dockerode, but the interface is promisified and with a fancier syntax.","archived":false,"fork":false,"pushed_at":"2023-09-25T15:54:11.000Z","size":1342,"stargazers_count":311,"open_issues_count":31,"forks_count":50,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-26T01:11:20.184Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/AgustinCB.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-07-05T21:43:49.000Z","updated_at":"2025-01-12T18:01:28.000Z","dependencies_parsed_at":"2024-01-10T20:11:10.241Z","dependency_job_id":"3f322e87-a471-4322-99a5-ba9a7632a21a","html_url":"https://github.com/AgustinCB/docker-api","commit_stats":{"total_commits":115,"total_committers":13,"mean_commits":8.846153846153847,"dds":"0.12173913043478257","last_synced_commit":"26495beb48de35a3e206d495570f2a79259708ec"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgustinCB%2Fdocker-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgustinCB%2Fdocker-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgustinCB%2Fdocker-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgustinCB%2Fdocker-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AgustinCB","download_url":"https://codeload.github.com/AgustinCB/docker-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246720505,"owners_count":20822913,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-01T07:01:26.443Z","updated_at":"2025-04-01T22:31:14.414Z","avatar_url":"https://github.com/AgustinCB.png","language":"TypeScript","readme":"# docker-api\n[![travis-ci](https://travis-ci.org/AgustinCB/docker-api.png?branch=master)](https://travis-ci.org/AgustinCB/docker-api)\n\nDocker Remote API driver for node.js. It uses the same modem than [dockerode](https://github.com/apocas/dockerode), but the interface is promisified and with a different syntax.\n\nSupport for:\n\n* **streams**\n* **stream demux**\n* **entities**\n* **run**\n* **tests**\n* **promises**\n* **full es6 support**\n\nThe current status of the package is in beta state. This module covers the full [API reference](https://docs.docker.com/engine/api/v1.30), including experimental stuff such as plugins.\n\nCheck the [reference](https://agustincb.github.io/docker-api/) and the [tests](https://github.com/AgustinCB/docker-api/tree/master/test) for full examples.\n\n## Installation\n```console\n$ npm install node-docker-api\n```\n\n## Usage\n\nYou can find more into the [examples folder](https://github.com/AgustinCB/docker-api/tree/master/examples)\n\n### Create, start, stop, restart and remove a container\n\n``` js\n'use strict';\nconst {Docker} = require('node-docker-api');\n\nconst docker = new Docker({ socketPath: '/var/run/docker.sock' });\n\ndocker.container.create({\n  Image: 'ubuntu',\n  name: 'test'\n})\n  .then(container =\u003e container.start())\n  .then(container =\u003e container.stop())\n  .then(container =\u003e container.restart())\n  .then(container =\u003e container.delete({ force: true }))\n  .catch(error =\u003e console.log(error));\n```\n\n### List, inspect and top containers\n\n``` js\n'use strict';\nconst {Docker} = require('node-docker-api');\n\nconst docker = new Docker({ socketPath: '/var/run/docker.sock' });\n\n// List\ndocker.container.list()\n   // Inspect\n  .then(containers =\u003e containers[0].status())\n  .then(container =\u003e container.top())\n  .then(processes =\u003e console.log(processes))\n  .catch(error =\u003e console.log(error));\n```\n\n### List, inspect and stat containers\n\n``` js\n'use strict';\nconst {Docker} = require('node-docker-api');\n\nconst docker = new Docker({ socketPath: '/var/run/docker.sock' });\n\n// List\ndocker.container.list()\n   // Inspect\n  .then(containers =\u003e containers[0].status())\n  .then(container =\u003e container.stats())\n  .then(stats =\u003e {\n    stats.on('data', stat =\u003e console.log('Stats: ', stat.toString()))\n    stats.on('error', err =\u003e console.log('Error: ', err))\n  })\n  .catch(error =\u003e console.log(error));\n```\n\n### Get logs of a container\n\n```js\n'use strict';\nconst {Docker} = require('node-docker-api');\n\nconst docker = new Docker({ socketPath: '/var/run/docker.sock' });\nlet container;\n\ndocker.container.create({\n  Image: 'ubuntu',\n  name: 'test'\n})\n  .then(container =\u003e container.logs({\n    follow: true,\n    stdout: true,\n    stderr: true\n  }))\n  .then(stream =\u003e {\n    stream.on('data', info =\u003e console.log(info))\n    stream.on('error', err =\u003e console.log(err))\n  })\n  .catch(error =\u003e console.log(error));\n```\n\n### Export a container\n\n``` js\nconst {Docker} = require('node-docker-api');\nconst fs = require('fs');\n\nconst docker = new Docker({ socketPath: '/var/run/docker.sock' });\nlet container;\n\ndocker.container.create({\n  Image: 'ubuntu',\n  name: 'test'\n})\n  .then(container =\u003e container.start())\n  .then(container =\u003e container.export())\n  .then(content =\u003e {\n    const file = fs.createWriteStream(\"container.tar\");\n    file.end(content)\n  })\n  .catch(error =\u003e console.log(error));\n```\n\n### Manipulate file system in a container\n\n``` js\n'use strict';\nconst fs = require('fs');\nconst {Docker} = require('node-docker-api');\n\nconst promisifyStream = stream =\u003e new Promise((resolve, reject) =\u003e {\n  stream.on('data', data =\u003e console.log(data.toString()))\n  stream.on('end', resolve)\n  stream.on('error', reject)\n});\n\nconst docker = new Docker({ socketPath: '/var/run/docker.sock' });\nlet container;\n\ndocker.container.create({\n  Image: 'ubuntu',\n  Cmd: [ '/bin/bash', '-c', 'tail -f /var/log/dmesg' ],\n  name: 'test'\n})\n  .then(container =\u003e container.start())\n  .then(_container =\u003e {\n    container = _container\n    return _container.fs.put('./file.tar', {\n      path: 'root'\n    })\n  })\n  .then(stream =\u003e promisifyStream(stream))\n  .then(() =\u003e container.fs.get({ path: '/var/log/dmesg' }))\n  .then(stream =\u003e {\n    const file = fs.createWriteStream(\"file.jpg\");\n    stream.pipe(file);\n    return promisifyStream(stream);\n  })\n  .then(() =\u003e container.status())\n  .then(container =\u003e container.stop())\n  .catch(error =\u003e console.log(error));\n```\n\n### Execute commands and kill containers\n\n``` js\n'use strict';\nconst {Docker} = require('node-docker-api');\n\nconst promisifyStream = stream =\u003e new Promise((resolve, reject) =\u003e {\n  stream.on('data', data =\u003e console.log(data.toString()))\n  stream.on('end', resolve)\n  stream.on('error', reject)\n});\n\nconst docker = new Docker({ socketPath: '/var/run/docker.sock' });\nlet _container;\n\ndocker.container.create({\n  Image: 'ubuntu',\n  Cmd: [ '/bin/bash', '-c', 'tail -f /var/log/dmesg' ],\n  name: 'test'\n})\n  .then(container =\u003e container.start())\n  .then(container =\u003e {\n    _container = container\n    return container.exec.create({\n      AttachStdout: true,\n      AttachStderr: true,\n      Cmd: [ 'echo', 'test' ]\n    })\n  })\n  .then(exec =\u003e {\n    return exec.start({ Detach: false })\n  })\n  .then(stream =\u003e promisifyStream(stream))\n  .then(() =\u003e _container.kill())\n  .catch(error =\u003e console.log(error));\n```\n\n### Build, inspect and remove an image\n\n``` js\n'use strict';\nconst {Docker} = require('node-docker-api');\nconst tar = require('tar-fs');\n\nconst promisifyStream = stream =\u003e new Promise((resolve, reject) =\u003e {\n  stream.on('data', data =\u003e console.log(data.toString()))\n  stream.on('end', resolve)\n  stream.on('error', reject)\n});\n\nconst docker = new Docker({ socketPath: '/var/run/docker.sock' });\n\nvar tarStream = tar.pack('/path/to/Dockerfile')\ndocker.image.build(tarStream, {\n  t: 'testimg'\n})\n  .then(stream =\u003e promisifyStream(stream))\n  .then(() =\u003e docker.image.get('testimg').status())\n  .then(image =\u003e image.remove())\n  .catch(error =\u003e console.log(error));\n```\n\n### Pull and check history of an image\n\n``` js\n'use strict';\nconst {Docker} = require('node-docker-api');\n\nconst promisifyStream = (stream) =\u003e new Promise((resolve, reject) =\u003e {\n  stream.on('data', (d) =\u003e console.log(d.toString()))\n  stream.on('end', resolve)\n  stream.on('error', reject)\n})\n\nconst docker = new Docker({ socketPath: '/var/run/docker.sock' })\n\nreturn docker.image.create({}, { fromImage: 'ubuntu', tag: 'latest' })\n  .then(stream =\u003e promisifyStream(stream))\n  .then(() =\u003e docker.image.get('ubuntu').status())\n  .then(image =\u003e image.history())\n  .then(events =\u003e console.log(events))\n  .catch(error =\u003e console.log(error))\n```\n\n### Fetch events from docker\n\n``` js\n'use strict'\nconst fs = require('fs');\nconst {Docker} = require('node-docker-api');\n\nconst promisifyStream = stream =\u003e new Promise((resolve, reject) =\u003e {\n    stream.on('data', data =\u003e console.log(data.toString()))\n    stream.on('end', resolve)\n    stream.on('error', reject)\n})\n\nconst docker = new Docker({ socketPath: '/var/run/docker.sock' })\n\ndocker.events({\n    since: ((new Date().getTime() / 1000) - 60).toFixed(0)\n})\n  .then(stream =\u003e promisifyStream(stream))\n  .catch(error =\u003e console.log(error))\n```\n","funding_links":[],"categories":["TypeScript","Uncategorized"],"sub_categories":["Uncategorized"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAgustinCB%2Fdocker-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FAgustinCB%2Fdocker-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FAgustinCB%2Fdocker-api/lists"}