Registry / devops / docker-modem

docker-modem

JSON →
library5.0.7jsnpmunverified

docker-modem is a foundational Node.js module that implements the network strategies necessary for interacting with the Docker Remote API. It provides a robust layer for managing connections to the Docker daemon, supporting various protocols including Unix sockets, HTTP, and SSH. This module is the underlying networking engine for popular libraries like `dockerode`. Currently at stable version 5.0.7, it receives maintenance updates to address dependencies and minor bug fixes, as evidenced by recent patch releases bumping dependencies and fixing callback issues. It differentiates itself by offering comprehensive connection options and handling the complexities of Docker's API communication, making it a reliable choice for building Docker-integrated applications in Node.js.

devopshttp-networking
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

The library's primary export is a default class `Modem`. For CommonJS, use `require('docker-modem')` directly, which returns the Modem class. For ESM, a default import is appropriate.

import Modem from 'docker-modem'; // For ESM

The `Modem` class is the default export. Destructuring `Modem` from a `require` call in CommonJS environments will result in `undefined`.

const Modem = require('docker-modem'); // For CJS

When using TypeScript, configuration options for the `Modem` constructor are typically defined by an interface like `ModemOptions`. This should be imported as a type for correctness and to avoid runtime errors.

import type { ModemOptions } from 'docker-modem';

Demonstrates initializing `docker-modem` with different connection methods (socket, HTTP, SSH) and performing a basic Docker API ping request.

const Modem = require('docker-modem'); // Connect via Unix socket (common on Linux/macOS) const modemSocket = new Modem({ socketPath: '/var/run/docker.sock' }); modemSocket.dial({ method: 'GET', path: '/_ping' }, (err, data) => { if (err) console.error('Ping socket error:', err.message); else console.log('Ping socket success:', data.toString()); }); // Connect via HTTP to a remote Docker host const modemHttp = new Modem({ host: 'http://127.0.0.1', port: 2375 }); // Assuming a Docker daemon exposed on 2375 modemHttp.dial({ method: 'GET', path: '/_ping' }, (err, data) => { if (err) console.error('Ping HTTP error:', err.message); else console.log('Ping HTTP success:', data.toString()); }); // Connect via SSH (requires SSH agent or credentials) // Note: This example uses a simplified host. Real-world usage requires proper SSH config. const modemSsh = new Modem({ protocol: 'ssh', host: 'ssh://localhost', // Replace with your SSH host port: 22, // sshOptions: { username: 'user', privateKey: '...' } // Uncomment and configure for real use }); modemSsh.dial({ method: 'GET', path: '/_ping' }, (err, data) => { if (err) console.error('Ping SSH error:', err.message); else console.log('Ping SSH success:', data.toString()); });
Debug
Known footguns
breakingVersion 5.0.3 introduced a critical security update for the underlying `ssh2` dependency. Older versions might be vulnerable to CVE-2023-48795, a Terrapin attack that could lead to prefix truncation.
gotchaConnecting to the Docker daemon requires correct configuration of `socketPath`, `host`/`port`, or `protocol`/`agent`. Incorrectly configured parameters will lead to connection failures.
gotchaWhen constructing API requests, ensure the `Content-Type` header is correctly specified, especially for requests that send a body (e.g., POST requests for image builds). The `Modem#dial` method now prefers provided `Content-Type` headers, which might change behavior if previous versions silently ignored it.
gotchaThe `buildQuerystring` utility now correctly handles root-level arrays. If your application previously relied on a different serialization behavior for arrays in querystrings, this change could alter API request parameters.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
12 hits · last 30 days
gptbot
4
ahrefsbot
4
chatgpt-user
2
script
1
googlebot
1
Resources