Dockerode is a comprehensive Node.js module designed for programmatically interacting with the Docker Remote API. It provides a robust, feature-rich interface for managing Docker containers, images, networks, and other Docker entities, aiming to implement all features exposed by the Docker Remote API. Key differentiators include its strong emphasis on native Node.js streams for operations like logs and execs, allowing for flexible stream manipulation and demultiplexing. It treats Docker entities (containers, images, execs) as distinct objects, and offers both callback and Promise-based interfaces, catering to various asynchronous programming styles. The package maintains a steady release cadence with frequent patch updates for dependencies and minor bug fixes, with the current stable version being 4.0.10. It is built to be highly testable and closely track changes in the official Docker API, acting as a direct wrapper that passes options to Docker and returns its responses largely unchanged.
npm install dockerodeVerified import paths — ran on the pinned version, not inferred.
This example demonstrates a full container lifecycle: pulling an image, creating, starting, attaching to logs, waiting for exit, and removing a Docker container using the Promise-based API.
Review your code for compatibility with the latest Docker API and dockerode's internal updates. Check the `docker-modem` changelog for more details on underlying network stack changes if issues arise.
Upgrade `dockerode` to version 4.0.2 or later to mitigate CVE-2023-48795.
Always explicitly set the `version` option in the `Docker` constructor, e.g., `'version: 'v1.41''. Match this version to your Docker daemon's API version for optimal compatibility. You can retrieve it via `docker version --format '{{.Server.APIVersion}}'`.Implement robust stream handling, including error listeners and 'end' event listeners. Use utility functions like `demuxStream` when dealing with multiplexed Docker streams. Ensure backpressure is managed if processing large amounts of data to prevent memory issues.
Verify your Docker daemon is running (`sudo systemctl start docker` or `docker start`). Check your Dockerode connection configuration (e.g., `socketPath`, `host`, `port`, or the `DOCKER_HOST` environment variable) and ensure it matches your Docker setup.
Double-check the container ID or name you are using. Ensure the container exists on the Docker daemon you are connected to by listing all containers (`docker ps -a`).
Update the `version` option in your `new Docker()` constructor to match your Docker daemon's API version (e.g., 'v1.41'). You can find your daemon's API version with `docker version --format '{{.Server.APIVersion}}'`.Ensure all asynchronous Dockerode operations are `await`ed or chained with `.then().catch()` appropriately. Always check that the resulting entity objects are valid before attempting subsequent operations on them to prevent `undefined` references.