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.
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
muslnode 18–226 runs
build_error
glibcnode 18–226 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());
});
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.