Giter VIP home page Giter VIP logo

node-docker-machine's Introduction

docker-machine

Programmatic API to Docker Machine (0.6.0+).
Wraps the docker-machine CLI.

node npm status Travis build status AppVeyor build status Dependency status JavaScript Style Guide

Table of Contents

Click to expand

Example

node example.js ls /

const Machine = require('docker-machine')
const cmd = process.argv.slice(2)
const machine = new Machine()

// Start if not already started
machine.start(function (err) {
  if (err) throw err

  // Execute a command
  machine.ssh(cmd, (err, result) => {
    if (err) throw err
    console.log(result)
  })
})

API

new Machine([name || opts])

Options:

  • name: defaults to DOCKER_MACHINE_NAME or "default"

machine.status((err, status) => ..)

Get lowercased status of the machine.

machine.isRunning((err, running) => ..)

True if status is running.

machine.start(err => ..)

Start machine, if not already running.

machine.stop(err => ..)

Stop machine, if not already stopped.

machine.kill(err => ..)

Kill machine, if not already stopped.

machine.env([opts], (err, result) => ..)

Get the environment variables to dictate that Docker should run a command against a particular machine. By default, env() returns the output from docker-machine env as-is. That is, a script which can be run in a subshell. Options:

  • shell: custom shell. Ignored if parse is true.
  • parse: if true, result will be a plain object:
{
  DOCKER_TLS_VERIFY: '1',
  DOCKER_HOST: 'tcp://<ip>:<port>',
  DOCKER_CERT_PATH: '<home>/.docker/machine/machines/<name>',
  DOCKER_MACHINE_NAME: '<name>'
}

machine.ssh(command, (err, result) => ..)

Run a command via SSH. The command can be a string or an array.

machine.inspect((err, result) => ..)

Get the output of docker-machine inspect as a plain object with camelCase properties.

Static methods

All of the above methods (from status() to inspect()) are also accessible as static methods, where the first argument is a name. For example:

const Machine = require('docker-machine')

Machine.env('default', { json: true }, (err, result) => {
  console.log(result.DOCKER_HOST)
})

Machine.create(name, driver[, options], (err) => ..)

Create a machine. Options are driver-specific.

const options = {
  'virtualbox-memory': '1024'
}

Machine.create('test', 'virtualbox', options, (err) => {
  if (err) throw err
})

Machine.list([opts], (err, machines) => ..)

Get all machines as an array, via docker-machine ls. Each machine is a plain object with camelCase properties.

{
  name: 'agent-1',                  // Machine name
  activeHost: false,                // Is the machine an active host?
  activeSwarm: false,               // Is the machine an active swarm master?
  active: '*',                      // Human-readable combination of the above
  driverName: 'virtualbox',         // Driver name
  state: 'running',                 // Machine state (running, stopped)
  url: 'tcp://192.168.99.101:2376', // Machine URL
  swarm: null,                      // Machine swarm name
  dockerVersion: 'v1.12.0',         // Docker Daemon version
  responseTime: 980,                // Time taken by the host to respond (ms)
  error: null                       // Machine errors
}

Options:

  • timeout: ls timeout in seconds (see docker/machine#1696)
  • inspect: if true, also include the metadata from inspect() for each machine:
{
  name: 'agent-1',                  // Plus all of the above
  driver: {                         // Driver metadata
    cpu: 1,
    memory: 2048,
    hostOnlyCidr: '192.168.99.1/24',
    ..
  },
  hostOptions: {                    // Various host options
    engineOptions: ..
    swarmOptions: ..
  }
}

Install

With npm do:

npm install docker-machine

License

MIT © 2016-present Vincent Weevers

node-docker-machine's People

Contributors

dikarel avatar greenkeeper[bot] avatar prakashvadrevu avatar vweevers avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

node-docker-machine's Issues

Unable to start a machine

I have a Meteor app that display all my machines and their status. If I want to stop a machine via the app there is not problems BUT I can't start a machine because I have this error:

Unable to start the VM: /usr/local/bin/VBoxManage startvm vbox-vial --type headless failed:
VBoxManage: error: The machine 'vbox-vial' is already locked by a session (or being locked or unlocked)
VBoxManage: error: Details: code VBOX_E_INVALID_OBJECT_STATE (0x80bb0007), component MachineWrap, interface IMachine, callee nsISupports
VBoxManage: error: Context: "LaunchVMProcess(a->session, sessionType.raw(), env.raw(), progress.asOutParam())" at line 589 of file VBoxManageMisc.cpp

So I tried to run the app and with the shell to start the machine and I got the same error.

Anyone has an idea how to resolve that ?

1.1.0

  • Update documentation
    • static vs instance methods
    • list()
    • stop()
    • Add description for env()
  • Add Machine.list() example from #2
  • Add Travis and AppVeyor
  • Maybe write a smoke test
  • List files in package.json

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on Greenkeeper branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please click the 'fix repo' button on account.greenkeeper.io.

An in-range update of hallmark is breaking the build 🚨

The devDependency hallmark was updated from 1.0.0 to 1.1.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

hallmark is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build passed (Details).
  • continuous-integration/appveyor/branch: AppVeyor build failed (Details).

Commits

The new version differs by 9 commits.

  • 7e1b2eb 1.1.0
  • 06a2e34 Also test 'hallmark --fix' on dependents
  • b6011c2 Add --ignore/-i option (in addition to package config)
  • 63979e3 Upgrade remark from ~10.0.1 to ~11.0.0 (#27)
  • 8a4e18f Upgrade remark-toc from ~5.1.1 to ~6.0.0 (#25)
  • c1d713d Upgrade remark-github from ~7.0.3 to ~8.0.0 (#26)
  • e93c81e Upgrade remark-validate-links from ~8.0.2 to ~9.0.1 (#31)
  • de87350 Smoke test dependents (#29)
  • 1a8c447 Upgrade deglob from ~3.1.0 to ^4.0.0 (#28)

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Kill a machine

I can't find how to do "docker-machine kill myMachine" is it a way to do it with node-docker-machine ?

When the app run in Docker it can't find the Docker machines

Expected behaviour

When I run the app in local (so not in Docker) I can list the Docker machines and interact with them with your good work.
capture d ecran 2017-02-06 a 09 35 11

Actual behaviour

And I transferred my app in Docker to see if everything works here too but I can't see the Docker machines despite the code is exactly the same.

I created the Machine like this:
import Machine from 'docker-machine';
I used this code to list them:

upsertCollectionMachines = Meteor.bindEnvironment(function() {
    Machine.list({
        inspect: true
    }, Meteor.bindEnvironment(function(err, machines) {
        if (typeof machines === "undefined") {
            console.error("Impossible to access 'machines' from 'Machine.list'");
        } else {
            machines.forEach(Meteor.bindEnvironment(function(machineInfo) {
                InfosMachines.upsert({
                    nameMachine: machineInfo.name,
                }, {
                    nameMachine: machineInfo.name,
                    stateMachine: machineInfo.state
                });
                console.log("Machines add");
            }));
        }
    }));
})

So maybe it's me who made something wrong (and I think so ) but if it's not me could you help me to figure out why it doesn't work ?

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on Greenkeeper branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet. We recommend using Travis CI, but Greenkeeper will work with every other CI service as well.

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please click the 'fix repo' button on account.greenkeeper.io.

Remove machine not in API?

Did I miss anything or is the 'docker-machine rm' command not available? If so, how do we remove a machine?

Thx!

plans for machine create?

I just stumbled on this while searching to see if a module existed before writing my own. Great stuff so far!

Any plans to implement the docker-machine create API? Creating/deleting machines with any of the supported drivers was one of the biggest parts I needed to build this for, but I'll surely end up needing the full API eventually. Before I go off and duplicate effort, I figured it was worth checking in to see what your plans are. I'd be happy just contribute here instead if you plan to build out the full API.

If you're open to collaboration, let's talk!

"spawn docker-machine ENOENT" when running the app into a Docker Machine

Hi,
This error appears when I try to execute Machine.list in an app who is in a Docker Machine.

CONTAINER ID        IMAGE                     COMMAND                  CREATED             STATUS              PORTS                      NAMES
30c6d792147e        jeromevi/mgmt-docker-ui   "/bin/sh -c 'bash ..."   4 minutes ago       Up 4 minutes        0.0.0.0:3005->80/tcp       mgmtdockergui_app_1
3780df4c4271        mongo:latest              "/entrypoint.sh mo..."   4 minutes ago       Up 4 minutes        0.0.0.0:27018->27017/tcp   mgmtdockergui_mongo_1

And I have this error spawn docker-machine ENOENT when I want to list the Machine. If I run the app outside of Docker there is no problems.

Any ideas ?

No result when ssh a docker run command

const vm1 = new Machine({ name: "vm1" });
vm1.ssh("docker run user/image", (err, result) => {
  if (err) throw err
  console.log(result)
});

Hello, this leave no result where the real command docker-machine ssh vm1 'docker run user/image' output something

TypeScript typings

Thanks for this great package.

Would you accept a PR providing TypeScript typings?

Cannot remove machine

How do I remove a machine?
I was reviewing the documentation and the code and I could not find the remove option.

I tried using the Machine.command but its not returning anything or working:

  Machine.command([`rm`, `${machineName}`], (err, result) => {
    console.log('error', err)
    console.log('result', result)
  })

Is there a way to remove a docker-machine?

No Type Definitions

Adding type definitions would add huge value. Several major IDEs are basing intellisense and code linting on Typescript definition files, even for non-typescript JS files. This makes libraries a breeze to use and can help increase adoption.

I may be writing some limited types for our own use. If they would help, or you need some more TS insight, let me know.

Thanks,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.