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.
npm install docker-modemVerified import paths — ran on the pinned version, not inferred.
Demonstrates initializing `docker-modem` with different connection methods (socket, HTTP, SSH) and performing a basic Docker API ping request.
Upgrade to `docker-modem@5.0.3` or higher immediately to mitigate the `ssh2` CVE. Ensure your `package.json` allows for this patch version or directly specify `"docker-modem": ">=5.0.3"`.
Always verify your Docker daemon's listening configuration. For Unix sockets, `socketPath` (e.g., `/var/run/docker.sock`) is common. For TCP/HTTP, ensure the `host` and `port` are accessible. For SSH, provide valid `protocol: 'ssh'` and host/port, possibly with `sshOptions` for authentication.
Explicitly set the `Content-Type` header in your request options for methods that send a body, if it's not being correctly inferred. For example, `{ method: 'POST', path: '/build', headers: { 'Content-Type': 'application/tar' } }`.Review any API calls that construct querystrings from JavaScript arrays using `docker-modem`'s internal utilities, or if you're passing arrays directly in the `querystring` option. Test to ensure the generated URLs match the expected Docker API format.
Ensure the Docker daemon is running (`sudo systemctl start docker` or `docker start`). Verify the `socketPath` in your Modem configuration matches the daemon's listening socket. Check file permissions on the socket (e.g., add user to `docker` group: `sudo usermod -aG docker $USER && newgrp docker`).
Inspect the Docker daemon logs (`journalctl -u docker` or `docker logs <container_id>`). Verify your API request payload and headers are correct. For long-running operations (like image builds or logs), ensure proper handling of streams and timeouts.
Ensure `const Modem = require('docker-modem');` is used for CommonJS and `new Modem(...)` is called. For ESM, ensure `import Modem from 'docker-modem';` is used. Do not attempt `const { Modem } = require('docker-modem');` as `Modem` is the default export.