mydockerjs
A javascript utility library for docker and docker-compose, it provides a simple javascript wrapper in order to execute docker commands and an api in order to use Docker with a node server.
Getting Started
npm install --save mydockerjs
to use in your projects.
The library provides :
- docker : a docker js library in order to execute docker commands
- imageMgr : an image util library to retrieve informations about installed docker images and push / pull images
- dockerCompose : a docker compose library to run docker compose commands and parse json objects in yaml docker-compose syntax
If you want to test, to edit or to try example:
git clone https://github.com/giper45/docker-js.git
in examples dir you'll find some example:
cd examples;
node <namejs>
Prerequisites
In order to use you should first install docker engine and docker-compose . The library also uses curl .
Windows Support (beta)
Version 1.8.0 and later supports the WindowDockerToolbox. In order to use it you've to run node inside the DockerToolbox Virtual Machine, then everything should work.
Library Limitations and future improvements
-
Windows: There is no support for HyperV Windows 10 Pro version but only Docker Toolbox.
-
Linux/Mac and docker-remote-API: Library uses the docker remote api version 24 and connects itself to /var/run/docker.sock unix socket. Actually there is no way to change these default parameters
-
Windows and docker-remote-API: If you're using Docker Toolbox there is an HTTPS connection to manage and certificates are required. Library uses default paths in order to find these parameters:
- Default Docker IP: 192.168.99.100
- Default Docker listening port: 2376
- Certificates path: %HOMEPATH%/.docker/machine/machines/default
Examples
All the api provides a simple syntax with callback function and params options :
Docker utils
Some utility function Import:
const du = dockerUtils;
Check if dockerEngine is running:
du;
Check if docker-cli / docker-compose commands are installed:
//Docker CLI // ASYNC MODE du; // SYNC MODE du //Return true if docker Cli is installed // Docker COMPOSE //ASYNC MODE du; //SYNC MODE du
Docker images
Import :
const dockerImages = imageMgr
Get images name :
//Get image names dockerImages;
Get detailed list :
//Get detailed list of images in javascript objectdockerImages
Get jsonList:
//Get json list of imagesdockerImages
Remove untagged images :
dockerImages
Each get function receives a callback and a paramsInput
Available options for the paramsInput are :
- onlytagged: if true returns only tagged images
- filterLabel : TBD
Docker library
Import :
const dockerJS = docker
Get active containers :
dockerJS
Remove all unactive containers :
dockerJS
Run a container :
dockerJS
run function accept imageName, callback and paramsInput. Available options :
- detached : if true add -d flag to docker run
- cmd : add a command to the end docker run
- name : add a name to running container
Example :
dockerJS
Docker exec a command :
dockerJS
Available options :
- detached: if true run the command in detached mode
Stop all containers:
dockerJS
Start all containers :
dockerJS
Create a new network :
var flags = driver : 'bridge' subnet : '192.168.1.1/24' dockerJS
Remove network :
var name = 'testRete' dockerJS
Network prune (destroy all inactive networks) :
dockerJS
Network List :
dockerJS
Get infos about a container :
//Select an existsent container name="existentContainer" dockerJS
docker-compose
To use :
dockerComposer = dockerComposer
The functions follows this convention :
dockerComposer
where pathContainingDockerComposeYaml where is located the docker-compose yaml that you want to up / down, callback is called when the docker-compose command finishes , dockerComposeLogF is a function called each time that docker-compose write a newline on the console (docker-compose writes all logs on stderr )
Check if a docker-compose lab is Running :
dockerComposer
docker-compose up :
dockerComposer
docker-compose down:
dockerComposer;
docker-compose exec:
const params = detached: false ;const dockerComposer = dockerComposer;const processRef = dockerComposer;
docker-compose start : TBD
docker-compose stop : TBD
Contributing :
Eslint with a relaxed version of Airbnb is used for syntax checking (https://github.com/airbnb/javascript ). Look at the .eslintrc for more informations about which rules are turned off. Before to send ant contribute pls check your code with eslint . Use github for any issue or improvement you like.
- Fork it!
- Create your feature branch: git checkout -b my-new-feature
- Check
- Commit your changes: git commit -am 'Add some feature'
- Push to the branch: git push origin my-new-feature
- Submit a pull request
Running the tests
TBD
License
MIT Licensed