
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
mydockerjs
Advanced tools
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.
npm install --save mydockerjs
to use in your projects.
The library provides :
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>
In order to use you should first install docker engine and docker-compose . The library also uses curl .
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.
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
All the api provides a simple syntax with callback function and params options :
function nameF(dependentFunctionParameters, callback, paramsInput)
Some utility function Import:
const du = require('mydockerjs').dockerUtils;
Check if dockerEngine is running:
du.isDockerEngineRunning((err, isRunning) => {
//DO SOMETHING
});
Check if docker-cli / docker-compose commands are installed:
//Docker CLI
// ASYNC MODE
du.isDockerCliInstalled((err, isInstalled) => {
// DO SOMETHING
});
// SYNC MODE
du.isDockerCliInstalledSync() //Return true if docker Cli is installed
// Docker COMPOSE
//ASYNC MODE
du.isDockerComposeInstalled((err, isInstalled) => {
// DO SOMETHING
});
//SYNC MODE
du.isDockerComposeInstalledSync()
Import :
const dockerImages = require('mydockerjs').imageMgr
Get images name :
//Get image names
dockerImages.getNames(function(err, json) {
utils.print(err,json)}, {onlytagged:true});
Get detailed list :
//Get detailed list of images in javascript object
dockerImages.getDetailedList(function(err, data) {
utils.print(err,data);
})
Get jsonList:
//Get json list of images
dockerImages.getJSONList(function(err, data) {
utils.print(err, data);
})
Remove untagged images :
dockerImages.removeUntagged(function(err, data) {
utils.print(err, data);
})
Each get function receives a callback and a paramsInput
Available options for the paramsInput are :
Import :
const dockerJS = require('mydockerjs').docker
Get active containers :
dockerJS.ps(function(err, dockerContainers) {
if(err) console.log(err)
else console.log(dockerContainers)
})
Remove all unactive containers :
dockerJS.rmAll(function(err, data) {
utils.print(err, data)
})
Run a container :
dockerJS.run('hello-world', function(err, data) {
if(err) {
console.log("Some err:")
console.log(data)
}
else {
console.log(data)
}
})
run function accept imageName, callback and paramsInput. Available options :
Example :
dockerJS.run('daindragon2/debian_useradd', function(err, data) {
if(err) {
console.log("some error");
console.log(err);
}
else {
console.log("runned")
console.log(data)
//Print running containers
dockerJS.ps(function(err, dockerContainers) {
if(err) console.log(err)
else console.log(dockerContainers)
})
}
}, {name:"theContainer", detached:true, cmd:'bash'})
Docker exec a command :
dockerJS.exec(nameContainer, command, callback, paramsInput)
Available options :
Stop all containers:
dockerJS.stopAll(function(err, data) {
utils.print(err, data)
})
Start all containers :
dockerJS.startAll(function(err, data) {
utils.print(err, data)
})
Create a new network :
var flags = {
driver : 'bridge',
subnet : '192.168.1.1/24'
}
dockerJS.createNetwork("testRete", function(err, data) {
utils.print(err, data)
}, flags)
Remove network :
var name = 'testRete'
dockerJS.removeNetwork(name, utils.print)
Network prune (destroy all inactive networks) :
dockerJS.networkPrune(utils.print)
Network List :
dockerJS.networkList(utils.print)
Get infos about a container :
//Select an existsent container
name="existentContainer"
dockerJS.getInfoContainer(name, utils.print)
To use :
dockerComposer = require('mydockerjs').dockerComposer
The functions follows this convention :
dockerComposer.functionName(
pathContainingDockerComposeYaml,
callback,
dockerComposeLogF
)
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.isRunning(path, (err, isRunning) => {
if(err) console.log(err);
else if (isRunning) console.log(path+' is running');
else console.log(path+' is not running');
}
docker-compose up :
dockerComposer.up(pathExample, utils.print, function(dataline) {
console.log(dataline)
})
docker-compose down:
dockerComposer.down(pathExample, utils.print, function(dataline) {
console.log(dataline) });
docker-compose exec:
const params = { detached: false };
const dockerComposer = require('mydockerjs').dockerComposer;
const processRef = dockerComposer.exec(PATH_DOCKER_COMPOSE, CONTAINER_NAME, COMMAND, (err) => {
console.log('ERR:');
console.log(err);
}, params, (dataline) => {
console.log(dataline);
});
docker-compose start : TBD
docker-compose stop : TBD
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.
TBD
MIT Licensed
FAQs
A javascript utility library for docker
The npm package mydockerjs receives a total of 551 weekly downloads. As such, mydockerjs popularity was classified as not popular.
We found that mydockerjs demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.