{"id":11415,"library":"node-docker-api","title":"Docker Remote API for Node.js","description":"node-docker-api is a Node.js driver for the Docker Remote API, offering a promisified interface for interacting with the Docker daemon's containers, images, networks, and other resources. It distinguishes itself from alternatives like dockerode by providing a promise-based API and a different syntax, while internally relying on the same robust modem for communication. The library fully supports essential Docker functionalities including stream handling (e.g., for logs and stats), stream demultiplexing, entity management, and offers full ES6 support. It aims to cover the complete Docker Engine API reference, including experimental features, and provides TypeScript type definitions. As of version 1.1.22, the package is officially in a 'beta state,' indicating that users should expect potential API adjustments or minor instabilities, although core functionality is generally stable. Release cadence is not explicitly defined but follows development during its beta phase.","status":"active","version":"1.1.22","language":"javascript","source_language":"en","source_url":"https://github.com/AgustinCB/docker-api","tags":["javascript","docker","api","node","typescript"],"install":[{"cmd":"npm install node-docker-api","lang":"bash","label":"npm"},{"cmd":"yarn add node-docker-api","lang":"bash","label":"yarn"},{"cmd":"pnpm add node-docker-api","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Provides the underlying communication layer for interacting with the Docker daemon.","package":"docker-modem","optional":false}],"imports":[{"note":"The main Docker client class is a named export. TypeScript users will prefer this.","wrong":"import Docker from 'node-docker-api';","symbol":"Docker","correct":"import { Docker } from 'node-docker-api';"},{"note":"CommonJS environments use named destructuring for the main Docker client.","wrong":"const Docker = require('node-docker-api');","symbol":"Docker (CommonJS)","correct":"const { Docker } = require('node-docker-api');"}],"quickstart":{"code":"import { Docker } from 'node-docker-api';\n\nconst docker = new Docker({ socketPath: '/var/run/docker.sock' });\n\nasync function manageContainer() {\n  let containerInstance;\n  try {\n    console.log('Creating container...');\n    const container = await docker.container.create({\n      Image: 'ubuntu',\n      name: 'test-node-api-container',\n      Cmd: ['tail', '-f', '/dev/null'] // Keep container running\n    });\n    containerInstance = container;\n    console.log(`Container '${container.id}' created.`);\n\n    console.log('Starting container...');\n    await container.start();\n    console.log(`Container '${container.id}' started.`);\n\n    console.log('Stopping container...');\n    await container.stop();\n    console.log(`Container '${container.id}' stopped.`);\n\n    console.log('Restarting container...');\n    await container.restart();\n    console.log(`Container '${container.id}' restarted.`);\n\n  } catch (error) {\n    console.error('An error occurred:', error);\n  } finally {\n    if (containerInstance) {\n      console.log('Deleting container...');\n      await containerInstance.delete({ force: true });\n      console.log(`Container '${containerInstance.id}' deleted.`);\n    }\n  }\n}\n\nmanageContainer();","lang":"typescript","description":"This example demonstrates the full lifecycle of a Docker container: creation, start, stop, restart, and forced removal, utilizing async/await with the promisified API."},"warnings":[{"fix":"Review the GitHub repository's release notes and changelog regularly. Pin dependencies to exact versions to prevent unexpected updates in production environments.","message":"Despite a 1.x version number, the package explicitly states it is in 'beta state'. This implies the API might not be fully stable, and minor breaking changes could occur in future minor versions.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure the Docker daemon is running. Verify `socketPath` (e.g., `/var/run/docker.sock` on Linux, `//./pipe/docker_engine` on Windows via WSL2, or a custom path), `host`, and `port` configurations match your Docker environment. For remote connections, ensure proper authentication and firewall rules.","message":"The Docker daemon connection parameters (e.g., `socketPath`, `host`, `port`) are crucial for proper functionality. Incorrect settings or an unreachable Docker daemon will result in connection errors.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always attach `data`, `error`, and `end` listeners to streams returned by methods like `container.logs()` or `container.stats()`. Ensure streams are properly consumed or unsubscribed from when no longer needed.","message":"When working with Docker streams (e.g., for logs or stats), proper event handling (`on('data')`, `on('error')`, `on('end')`) is critical to consume data and prevent memory leaks. Streams must be explicitly closed or allowed to end.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Start the Docker daemon. Verify the `socketPath` in your Docker constructor (e.g., `/var/run/docker.sock` for Linux/macOS, `//./pipe/docker_engine` for Windows via WSL2, or check Docker Desktop settings for alternative paths).","cause":"The Docker daemon is either not running, or the specified socket path is incorrect for your operating system or Docker setup.","error":"Error: connect ECONNREFUSED /var/run/docker.sock"},{"fix":"Ensure `new Docker({ /* config */ })` is called and assigned to the `docker` variable before attempting to use its properties and methods like `docker.container.create`.","cause":"The `docker` object was not correctly initialized, or a method like `container` was accessed before the `Docker` client was properly instantiated.","error":"TypeError: Cannot read properties of undefined (reading 'create')"},{"fix":"Check that the container ID or name is correct and that the container is currently running or exists. List active containers using `docker.container.list()` to verify its presence.","cause":"The specified container ID or name does not exist on the Docker daemon, or it has already been removed.","error":"Error: (HTTP code 404) no such container - No such container: [container-id]"}],"ecosystem":"npm"}