dockops 
docker convenience functions on top of dockerode
Table of Contents generated with DocToc
var dockops = require('dockops')
var docker = dockops.createDocker({ dockerhost: dockerhost });
var images = new dockops.Images(docker);
dockops.logEvents(images, 'verbose');
var containers = new dockops.Containers(docker);
dockops.logEvents(containers, 'verbose');
build('test:uno', testUnoTar, function () {
build('toast:uno', toastUnoTar, function () {
containers.run(.. // run test:uno and toast:uno containers
containers.listRunning(function (err, res) {
inspect(res);
containers.stopRemoveGroup('test', function (err, res) {
containers.listRunning(function (err, res) {
inspect(res);
http.request({ port: 49222 }, function (res) {
console.log('--------------------------')
inspect({ status: res.statusCode, headers: res.headers })
res.pipe(process.stdout)
}).end()
})
})
})
})
})

Installation
npm install dockops
API
dockops::Containers(docker) → {Object}
Creates a new containers instance that will use the given docker instance to communicate with docker.
Parameters:
| Name | Type | Description |
|---|---|---|
docker |
Object | dockerode instance to communicate with docker |
Returns:
initialized containers
dockops::activePorts(cb)
Lists all running containers by the ports they expose.
Parameters:
| Name | Type | Description |
|---|---|---|
cb |
function | called back with list of containers hashed by their port number |
dockops::clean(id, cb)
Stops and/or kills and then removes a container.
Heavy machinery clean operation. It was useful when running on arch with docker not always working as promised. This may not be needed anymore as docker got more stable.
Parameters:
| Name | Type | Description |
|---|---|---|
id |
string | container id |
cb |
function | called back after container was cleaned or maximum attempts were exceeded |
dockops::create(opts, cb)
Creates a docker container according to given opts.
Parameters:
| Name | Type | Description |
|---|---|---|
opts |
Object | creation options passed to dockerode |
cb |
function | called back when container was created |
dockops::listAll(cb)
Lists all docker containers.
Parameters:
| Name | Type | Description |
|---|---|---|
cb |
function | called back with list of containers |
dockops::listGroup(group, cb)
Lists all containers that were created from images belonging to a given group.
Parameters:
| Name | Type | Description |
|---|---|---|
group |
string | group for which to list containers |
cb |
function |
dockops::listGroupRunning(group, cb)
Lists all running docker containers of the given group
Parameters:
| Name | Type | Description |
|---|---|---|
group |
string | group for which to list running containers |
cb |
function | called back with list of running containers |
dockops::listImage(imageName, cb)
Lists all containers that were created from a particular image.
Parameters:
| Name | Type | Description |
|---|---|---|
imageName |
string | name of image for which to list containers |
cb |
function |
dockops::listRunning(cb)
Lists all running docker containers
Parameters:
| Name | Type | Description |
|---|---|---|
cb |
function | called back with list of running containers |
dockops::listStopped(cb)
Lists all stopped docker containers
Parameters:
| Name | Type | Description |
|---|---|---|
cb |
function | called back with list of stopped containers |
dockops::remove(id, cb)
Removes the container with the given id
Parameters:
| Name | Type | Description |
|---|---|---|
id |
string | id of the container to remove |
cb |
function | called back when container was removed |
dockops::removeGroup(group, cb)
Removes all containers that were created from images belonging to a given group.
Parameters:
| Name | Type | Description |
|---|---|---|
group |
string | group for which to remove containers |
cb |
function |
dockops::removeImage(name, cb)
Removes all containers that were created from the image with the given name
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | name of the image for which to remove containers |
cb |
function | called back when containers were removed |
dockops::removeStopped(cb)
Removes all stopped containers.
Parameters:
| Name | Type | Description |
|---|---|---|
cb |
function | called back when all stopped containers where removed. |
dockops::run(opts, cb)
Creates and starts a container.
Parameters:
| Name | Type | Description | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
opts |
Object | container creation and start options Properties
|
||||||||||||||||
cb |
function | called when the container was started - with an error if it failed |
dockops::stop(id, cb)
Stops the container with the given id
Parameters:
| Name | Type | Description |
|---|---|---|
id |
string | id of the container to stop |
cb |
function | called back when container was stopd |
dockops::stopGroup(group, cb)
Stops all containers that were created from images belonging to a given group.
Parameters:
| Name | Type | Description |
|---|---|---|
group |
string | group for which to stop containers |
cb |
function |
dockops::stopImage(name, cb)
Stops all containers that were created from the image with the given name
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | name of the image for which to stop containers |
cb |
function | called back when containers were stopped |
dockops::stopRemove(id, cb)
Stops and then removes the container with the given id
Parameters:
| Name | Type | Description |
|---|---|---|
id |
string | id of the container to stop and remove |
cb |
function | called back when container was stopped and removed |
dockops::stopRemoveGroup(group, cb)
Stops and then removes all containers created from images belonging to a given group.
Parameters:
| Name | Type | Description |
|---|---|---|
group |
string | group for which to remove containers |
cb |
function |
dockops::stopRemoveImage(name, cb)
Stops and then removes all containers that were created from the image with the given name
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | name of the image for which to stop and remove containers |
cb |
function | called back when containers were stopped and removed |
dockops::createDocker(dockerhost) → {Object}
Convenience function to create a dockerode instance.
Parameters:
| Name | Type | Argument | Description |
|---|---|---|---|
dockerhost |
string |
<optional> |
(default: |
Returns:
dockerode instance
dockops::Images(docker) → {Object}
Creates a new images instance that will use the given docker instance to communicate with docker.
Parameters:
| Name | Type | Description |
|---|---|---|
docker |
Object | dockerode instance to communicate with docker |
Returns:
initialized images
dockops::build(tarStream, image, cb)
Builds an image from the stream provided. All intermediate containers are removed after the image was created.
All events from the tar stream are re-emitted, especially useful if it was created with dockerify.
Parameters:
| Name | Type | Description |
|---|---|---|
tarStream |
Stream | the tar stream that contains the project files and a |
image |
string | then name under which to tag the created image |
cb |
function | called back when image is created or with an error if one occurred |
dockops::buildStream(tarStream, image, cb)
Builds an image from the stream provided. All intermediate containers are removed after the image was created.
Note: if you want all events from the tar stream to be propagated, i.e. if it was created with dockerify, use build instead.
Parameters:
| Name | Type | Description |
|---|---|---|
tarStream |
Stream | the tar stream that contains the project files and a |
image |
string | then name under which to tag the created image |
cb |
function | called back when image is created or with an error if one occurred |
dockops::deserializeImageName(name) → {Object}
Deserializes the given image name into an object.
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | the name of the image, expected to be in the format: |
Returns:
object of the format: { group: 'group', tag: 'tag' }
dockops::list(cb)
Lists docker images.
Parameters:
| Name | Type | Description |
|---|---|---|
cb |
function | called back with list of images |
dockops::listGroup(group, cb)
Lists docker images for given group.
Parameters:
| Name | Type | Description |
|---|---|---|
group |
string | name of the group of images to list |
cb |
function | called back with list of images |
dockops::removeGroup(group, cb)
Removes all images for the given group
Parameters:
| Name | Type | Description |
|---|---|---|
group |
string | name of the group of images to remove |
cb |
function | called back when the images were removed |
dockops::logEvents(events, level)
Logs events emitted with npm log at the given level.
debug events are logged as verbose.
Parameters:
| Name | Type | Description |
|---|---|---|
events |
EventEmitter | events that should be logged |
level |
string | (default: verbose) level of logging |
dockops::portBindings(exposePort, hostPort) → {Object}
Helper function to creat a proper tcp portbinding for the given ports
Parameters:
| Name | Type | Argument | Description |
|---|---|---|---|
exposePort |
number | the port of the docker container to expose to the host |
|
hostPort |
number |
<optional> |
(default: |
Returns:
the port binding to pass to docker when creating a container
generated with docme
License
MIT