dockermachine-cli-js is a Node.js wrapper library that provides a programmatic interface for interacting with the `docker-machine` command-line tool. It abstracts the execution of `docker-machine` commands, offering both Promise-based and callback-style APIs for convenience. The current stable version is 3.0.5. While releases appear infrequent, the project has seen recent updates in the 3.x series, indicating active maintenance. A key differentiator is its ability to parse the output of commands like `ls` into structured JavaScript objects, rather than just returning raw string output. It also ships with TypeScript type definitions, enabling a robust development experience for TypeScript users. This library is specifically useful for automating `docker-machine` provisioning and management tasks within Node.js applications, offering a more structured approach than direct `child_process` execution. A crucial prerequisite is the external installation and availability of the `docker-machine` CLI tool on the system's PATH, as this library acts as a thin wrapper around it.
npm install dockermachine-cli-jsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize `DockerMachine` with AWS EC2 driver options, create a new Docker Machine, list existing machines, and then clean up by removing the created machine, using TypeScript and Promises.
Install `docker-machine` via official Docker documentation for your operating system (e.g., Docker Desktop or standalone installation). Verify installation by running `docker-machine version` in your terminal.
Ensure that the first argument passed to the `Options` constructor is an object containing key-value pairs representing `docker-machine` command line flags (e.g., `{ 'driver': 'amazonec2', 'amazonec2-access-key': 'XYZ' }`).For TypeScript projects, use `import { DockerMachine, Options } from 'dockermachine-cli-js';`. For CommonJS, `const DockerMachineCLI = require('dockermachine-cli-js');` should still work, but be aware that `Options` and `DockerMachine` are properties of the exported object.Install `docker-machine` on your system according to the official Docker documentation. After installation, verify it's available by running `docker-machine version` in your terminal. If installed but not found, ensure its executable directory is added to your system's PATH.
For TypeScript/ESM, use named imports: `import { DockerMachine, Options } from 'dockermachine-cli-js';` then `new Options(...)`. For CommonJS, ensure `const DockerMachineCLI = require('dockermachine-cli-js');` is used and then `new DockerMachineCLI.Options(...)`.Always append a `.catch(error => { console.error('Command failed:', error); })` to your `dockerMachine.command()` calls to properly handle errors and prevent unhandled promise rejections.