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.
npm install node-docker-apiVerified import paths — ran on the pinned version, not inferred.
This example demonstrates the full lifecycle of a Docker container: creation, start, stop, restart, and forced removal, utilizing async/await with the promisified API.
Review the GitHub repository's release notes and changelog regularly. Pin dependencies to exact versions to prevent unexpected updates in production environments.
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.
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.
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).
Ensure `new Docker({ /* config */ })` is called and assigned to the `docker` variable before attempting to use its properties and methods like `docker.container.create`.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.