dockerjs

command module
v0.0.0-...-2f220be Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2016 License: Apache-2.0 Imports: 4 Imported by: 0

README

dockerjs

Docker.js is a javascript runtime for docker. It allows you to write javascript programs that orchestrate docker containers. Docker.js is also an interactive javascript shell that lets you interact with your Docker runtime.

Installation

$ go get github.com/jsr/dockerjs
$ dockerjs 

In order to run docker.js, you'll need a docker host available and your ENV setup so that the docker client API can reach it.

$ ./dockerjs
Docker.js shell version 0.0.1
Type help() to get a list of builtin commands

You can create a new container

> c = new Container("redis", "my-first-container") 
{
  "ID": "76223d0a50e53f4ca0159767aff0db12bac2922b5fde300f38c13f2e3864dd0e",
  "image": "redis",
  "name": "my-first-container"
}

You can register callbacks on container events

> c.on('start', function(event) { print("hello world!"); })

Now we'll start the container. You should see "hello world!" printed when the start event hits.

> c.run()
>
hello world!
>

You can get a list of all of the containers in the runtime

> Container.all()
[
  {
    "ID": "76223d0a50e53f4ca0159767aff0db12bac2922b5fde300f38c13f2e3864dd0e",
    "image": "redis",
    "name": "/my-first-container"
  }
]
>

You can also search for a specific container by ID (or prefix of ID)

> Container.findByID("76223d0a50e5")
{
  "ID": "76223d0a50e53f4ca0159767aff0db12bac2922b5fde300f38c13f2e3864dd0e",
  "image": "redis",
  "name": "/my-first-container"
}

High level API

function description
new Container(image,name) Creates a new container
Container.all() returns a list of all running containers
Container.findByID(id) returns container matching the specified id
Container.match(fn) fn is a function which is evaluated against each running container. matched containers are returned
Container.prototype.run() starts the container
Container.prototype.on(event, fn) calls fn when the specified event is raised by the container

Low level API

Docker.js exposes some low level API's that let you access the docker runtime.

function description
list() -> []container Returns a list of all running containers
create(config, hostConfig, networkingConfig, name ) -> container Creates a new container. Will pull image if it's not there
run(id) Starts the specified container
require(filename) load a .js file and evaluate it
print(string) prints to stdout
sleep(millis) sleeps for miillis milliseconds
listen(id, event, callback) registers a callback function that will be invoked when the specified event is emitted by the specified container id

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL