$ show apocas/dockerode
dockerode is a Node.js library that provides a comprehensive client for the Docker Engine API. It is architected around entity objects (Container, Image, Volume, Network, Service, Secret, Config, Plugin, Node, Task, Exec) that encapsulate the corresponding Docker API endpoints. The library relies on docker-modem for HTTP transport and supports both Unix sockets and TCP connections with TLS. It offers dual callback and Promise-based interfaces for all operations, allowing flexible integration patterns. A standout feature is its sophisticated stream handling. The library passes raw HTTP streams directly to the user, enabling advanced patterns like stream demultiplexing and piping. It supports HTTP connection hijacking for interactive exec and attach sessions, providing true bidirectional stdin/stdout/stderr communication. For modern Docker builds, it includes a BuildKit integration layer (lib/buildkit.js, lib/session.js) that transparently decodes protobuf status messages and handles gRPC session upgrades, demonstrating high craftsmanship in protocol handling. The codebase is actively maintained, with CI testing against Node.js 16 through 22. It has a comprehensive test suite covering containers, images, networks, volumes, services, and swarm operations. While it retains some legacy patterns (extensive use of var, dual callback/Promise APIs), the core architecture is clean, the reusable components are genuinely extractable, and the overall quality is strong. It is a mature, feature-rich SDK that faithfully implements the Docker Remote API.
The LLM identified 5 files worth highlighting for reuse:
Provides transparent decoding of BuildKit protobuf status messages from Docker build streams. The followProgress function acts as a drop-in replacement for modem.followProgress, automatically detecting and decoding moby.buildkit.trace messages into human-readable log events. This module is completely isolated and could be extracted to handle BuildKit output in any context (CLI, CI system).
Handles the HTTP Upgrade to h2c (HTTP/2 cleartext) and creates a gRPC server on the hijacked socket to authenticate BuildKit sessions. This is a sophisticated, isolated pattern for negotiating advanced Docker protocols. It demonstrates deep understanding of HTTP connection hijacking and gRPC server injection.
The prepareBuildContext function encapsulates the logic for creating a Docker build context. It reads a .dockerignore file, filters source files accordingly, creates a tar archive, and compresses it with gzip. This is a standard, reusable pattern for any tool that needs to send build contexts to a Docker daemon.
The attach and exec methods support a hijack option that upgrades the HTTP connection to a raw TCP socket. This allows for true bidirectional stdin/stdout/stderr communication, overcoming the limitations of standard HTTP streaming. This is a sophisticated pattern for interactive container management.
The run method orchestrates the entire docker run workflow (create, attach, start, wait) into a single high-level operation. It provides both callback and Promise interfaces and emits lifecycle events (container, stream, start, data). This is a well-crafted example of composing multiple API calls into a cohesive workflow.