Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thlorenz/dockops
docker convenience functions on top of dockerode
https://github.com/thlorenz/dockops
Last synced: 15 days ago
JSON representation
docker convenience functions on top of dockerode
- Host: GitHub
- URL: https://github.com/thlorenz/dockops
- Owner: thlorenz
- License: mit
- Created: 2014-04-11T15:08:27.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-04-23T20:28:19.000Z (over 10 years ago)
- Last Synced: 2024-10-18T01:35:41.756Z (19 days ago)
- Language: JavaScript
- Homepage: https://github.com/thlorenz/dockops
- Size: 1 MB
- Stars: 14
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dockops [![build status](https://secure.travis-ci.org/thlorenz/dockops.png)](http://travis-ci.org/thlorenz/dockops)
docker convenience functions on top of dockerode
**Table of Contents** *generated with [DocToc](http://doctoc.herokuapp.com/)*
- [Installation](#installation)
- [API](#api)
- [dockops::Containers(docker) → {Object}](#dockopscontainersdocker-→-{object})
- [dockops::Containers::activePorts(cb)](#dockopscontainersactiveportscb)
- [dockops::Containers::clean(id, cb)](#dockopscontainerscleanid-cb)
- [dockops::Containers::create(opts, cb)](#dockopscontainerscreateopts-cb)
- [dockops::Containers::listAll(cb)](#dockopscontainerslistallcb)
- [dockops::Containers::listGroup(group, cb)](#dockopscontainerslistgroupgroup-cb)
- [dockops::Containers::listGroupRunning(group, cb)](#dockopscontainerslistgrouprunninggroup-cb)
- [dockops::Containers::listImage(imageName, cb)](#dockopscontainerslistimageimagename-cb)
- [dockops::Containers::listRunning(cb)](#dockopscontainerslistrunningcb)
- [dockops::Containers::listStopped(cb)](#dockopscontainersliststoppedcb)
- [dockops::Containers::remove(id, cb)](#dockopscontainersremoveid-cb)
- [dockops::Containers::removeGroup(group, cb)](#dockopscontainersremovegroupgroup-cb)
- [dockops::Containers::removeImage(name, cb)](#dockopscontainersremoveimagename-cb)
- [dockops::Containers::removeStopped(cb)](#dockopscontainersremovestoppedcb)
- [dockops::Containers::run(opts, cb)](#dockopscontainersrunopts-cb)
- [dockops::Containers::stop(id, cb)](#dockopscontainersstopid-cb)
- [dockops::Containers::stopGroup(group, cb)](#dockopscontainersstopgroupgroup-cb)
- [dockops::Containers::stopImage(name, cb)](#dockopscontainersstopimagename-cb)
- [dockops::Containers::stopRemove(id, cb)](#dockopscontainersstopremoveid-cb)
- [dockops::Containers::stopRemoveGroup(group, cb)](#dockopscontainersstopremovegroupgroup-cb)
- [dockops::Containers::stopRemoveImage(name, cb)](#dockopscontainersstopremoveimagename-cb)
- [dockops::createDocker(dockerhost) → {Object}](#dockopscreatedockerdockerhost-→-{object})
- [dockops::Images(docker) → {Object}](#dockopsimagesdocker-→-{object})
- [dockops::Images::build(tarStream, image, cb)](#dockopsimagesbuildtarstream-image-cb)
- [dockops::Images::buildStream(tarStream, image, cb)](#dockopsimagesbuildstreamtarstream-image-cb)
- [dockops::Images::deserializeImageName(name) → {Object}](#dockopsimagesdeserializeimagenamename-→-{object})
- [dockops::Images::list(cb)](#dockopsimageslistcb)
- [dockops::Images::listGroup(group, cb)](#dockopsimageslistgroupgroup-cb)
- [dockops::Images::removeGroup(group, cb)](#dockopsimagesremovegroupgroup-cb)
- [dockops::logEvents(events, level)](#dockopslogeventsevents-level)
- [dockops::portBindings(exposePort, hostPort) → {Object}](#dockopsportbindingsexposeport-hostport-→-{object})
- [License](#license)```js
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()
})
})
})
})
})
```[full example](https://github.com/thlorenz/dockops/blob/master/example/create-wipe.js)
![output](https://github.com/thlorenz/dockops/raw/master/assets/output.gif)
## 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
- Source:
Returns:
initialized containers
Type
Object
dockops::Containers::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
- Source:
dockops::Containers::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
- Source:
dockops::Containers::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
- Source:
dockops::Containers::listAll(cb)Lists all docker containers.
Parameters:
Name
Type
Description
cb
function
called back with list of containers
- Source:
dockops::Containers::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
- Source:
dockops::Containers::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
- Source:
dockops::Containers::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
- Source:
dockops::Containers::listRunning(cb)Lists all running docker containers
Parameters:
Name
Type
Description
cb
function
called back with list of running containers
- Source:
dockops::Containers::listStopped(cb)Lists all stopped docker containers
Parameters:
Name
Type
Description
cb
function
called back with list of stopped containers
- Source:
dockops::Containers::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
- Source:
dockops::Containers::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
- Source:
dockops::Containers::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
- Source:
dockops::Containers::removeStopped(cb)Removes all stopped containers.
Parameters:
Name
Type
Description
cb
function
called back when all stopped containers where removed.
- Source:
dockops::Containers::run(opts, cb)Creates and starts a container.
Parameters:
Name
Type
Description
opts
Object
container creation and start options
Properties
Name
Type
Argument
Description
create
Object
creation options passed to dockerode
start
Object
start options passed to
container.start
startRetries
Object
<optional>
(default: 0) determines how many times we retry to start the container in case it fails
cb
function
called when the container was started - with an error if it failed
- Source:
dockops::Containers::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
- Source:
dockops::Containers::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
- Source:
dockops::Containers::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
- Source:
dockops::Containers::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
- Source:
dockops::Containers::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
- Source:
dockops::Containers::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
- Source:
dockops::createDocker(dockerhost) → {Object}
Parameters:
Name
Type
Argument
Description
dockerhost
string
<optional>
(default:
'unix:///var/run/docker.sock'
) the docker host can also behttp
ortcp
- Source:
Returns:
dockerode instance
Type
Object
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
Type
Object
dockops::Images::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
Dockerfile
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::Images::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
Dockerfile
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::Images::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:
'group:tag'
.
- Source:
Returns:
object of the format:
{ group: 'group', tag: 'tag' }
Type
Object
dockops::Images::list(cb)Lists docker images.
Parameters:
Name
Type
Description
cb
function
called back with list of images
- Source:
dockops::Images::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
- Source:
dockops::Images::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
- Source:
dockops::logEvents(events, level)Logs events emitted with npm log at the given level.
debug
events are logged asverbose
.Parameters:
Name
Type
Description
events
EventEmitter
events that should be logged
level
string
(default: verbose) level of logging
error|warn|info|verbose|silly
- Source:
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:
0
which causes docker to pick a port) the host port to which to bind the exposed port
- Source:
Returns:
the port binding to pass to docker when creating a container
Type
Object*generated with [docme](https://github.com/thlorenz/docme)*
## License
MIT