npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

docker-service-api

v17.12.19

Published

Acesso a API docker via node js

Readme

Docker API Swarm

Install

$ npm install docker-service-api

Usage

const Host = require('docker-service-api').Host;
const RegistryAuth = require('docker-service-api').RegistryAuth;

const Service = require('docker-service-api').Service;
const Network = require('docker-service-api').Network;
const Node = require('docker-service-api').Node;
const System = require('docker-service-api').System;
const Container = require('docker-service-api').Container;
const Image = require('docker-service-api').Image;
const Task = require('docker-service-api').Task;
const Swarm = require('docker-service-api').Swarm;

Service

Hello World

const service = new Service();

service.name = 'hello-world';
service.replicas = 5;
service.image = 'tutum/hello-world';
service.publish = ['8080:80'];
service
    .create()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));

Set Host Swarm

const service = new Service();
const service = new Service(new Host('host', port));

HTTPS, Cert, Key, CA


const host = new Host('IP', 'PORT', {
    key : fs.readFileSync(`${process.env.CERS}/key.pem`),
    cert : fs.readFileSync(`${process.env.CERS}/cert.pem`),
    ca : fs.readFileSync(`${process.env.CERS}/ca.pem`)
});

const swarm = new Swarm();

Set Authentication Registry

const service = new Service();

service.name = 'hello-world';
service.replicas = 5;
service.image = 'tutum/hello-world';
service.publish = ['8080:80'];

/**
* Registry username, password and servername
*/
service.registryAuth = new RegistryAuth('username', 'password', 'servername');

service
    .create()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));
    

List Services

const service = new Service();

service
    .ls()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));
    

Inspect Services

const service = new Service();

service.id = 'ID';

service
    .inspect()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));

Remove Services

const service = new Service();

service.id = 'ID';

service
    .rm()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));

Network

Create Network

const network = new Network();

network.name = 'my_network_1';
network.driver = 'overlay';

network
    .create()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));
    

List Network

const network = new Network();

network
    .ls()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));
    

Inspect Network

const network = new Network();

network.id = 'ID';

network
    .inspect()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));

Prune Network

const network = new Network();

network
    .prune()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));

Remove Network

const network = new Service();

network.id = 'ID';

network
    .rm()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));

Node

List Node

const node = new Node();

node
    .ls()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));
    

Inspect Node

const node = new Node();

node.id = 'ID';

node
    .inspect()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));

Swarm

Info Swarm

const swarm = new Swarm();

swarm
    .info()
    .then(res => {
        console.log(res.JoinTokens.Worker) // Token Worker
        return Promise.resolve(res);
    })
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));
    

Join Swarm

const swarm = new Swarm(new Host('IP', 4243));

swarm.JoinToken = 'SWMTKN-1-43fphmejjpl ....';
swarm.AdvertiseAddr = '10.172.79.47';
swarm
    .join()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));

Leave Swarm

const swarm = new Swarm(new Host('IP', 4243));

swarm
    .leave()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));

Init Swarm


const swarm = new Swarm();

swarm
    .init()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));

Container

Create Container / Run

/**
* Create Container
*/

const container = new Container();

container.name = 'hello_name';
container.image = 'tutum/hello-world';
container.publish = ['8080:80/tcp'];
container.volumes = ['/tmp:/tmp'];
container.privileged = true;
container.dns = ['8.8.8.8'];
container.dnsSearch = ['my.example.com'];
container.volumesFrom = ['datastore'];
container.links = ['mongo:mongo'];

//Labels
container.labels = {
    TOTVSIDWILLLLL : "0123456789"
}

container.logDriver = 'gelf'; // or 'syslog' or etc...

container.logOpt = ['gelf-address=udp://[IP]:5555', ...]; // or ['syslog-address=tcp+tls://192.168.1.3:514'] or etc...

container.Entrypoint = ['/bin/bash', 'sleep', '100000']

container.Cmd = ['/bin/bash', 'sleep', '100000']

container
    .run()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));
    

Inspect Container

const container = new Container();

container.name = 'hello-world';

container
    .inspect()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));
    

Kill Container

const container = new Container();

container.name = 'hello-world'; 

container
    .kill()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));

Logs Container

const container = new Container();

container.name = 'hello-world';

container
    .logs()
    .then(stream => {
        stream.on('data', data => console.log(data.toString()));
    })
    .catch(err => console.error(`ERRO: ${err}`));

Lista os Container

const container = new Container();

//Filters
container.filters = {
    label : ["Key=Value"]
}

container
    .ls()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));

// OR

container
    .ps()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));

Pause Container

const container = new Container();

container.name = 'hello-world'; 

container
    .pause()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));

Prune Container

const container = new Container();

container
    .prune()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));

Remove Container

const container = new Container();

container.name = 'hello-world';

container
    .rm()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));

Start Container

const container = new Container();

container.name = 'hello-world'; 

container
    .start()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));

Stats Container

const container = new Container();

container.name = 'hello-world';

container
    .stats()
    .then(stream => {
        stream.on('data', data => console.log(JSON.parse(data)));
    })
    .catch(err => console.error(`ERRO: ${err}`));

Stop Container

const container = new Container();

container.name = 'hello-world';

container
    .stop()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));

Top Container

const container = new Container();

container.name = 'hello-world'; 

container
    .top()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));

Unpause Container

const container = new Container();

container.name = 'hello-world'; 

container
    .unpause()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));

Wait Container

const container = new Container();

container.name = 'hello-world'; 

container
    .wait()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));

Attach Container

const container = new Container();

container.name = 'hello-world';

container
    .attach()
    .then(stream => {
        stream.on('data', data => console.log(data.toString()));
    })
    .catch(err => console.error(`ERRO: ${err}`));

Task

List Task

const task = new Task();
task
    .ls()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));

List Task

const task = new Task();

task.id = 'y2dvvwkr9c9uoqtjbfu5behva';

task
    .inspect()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));

Image

Remove Image

const image = new Image();

image.id = 'c9a8375cc12a';

image
    .rm()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));

//OR

//image
//    .rmi()
//    .then(console.log)
//    .catch(err => console.error(`ERRO: ${err}`));
    

Pull Image

const image = new Image();

image.image = 'nginx:latest';

image
    .pull()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));

Prune Image

const image = new Image();
image
    .prune()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));

Lista Image

const image = new Image();
image
    .ls()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));
    

History Image

const image = new Image();

image.id = 'c9a8375cc12a';

image
    .history()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));
    

Inspect Image

const image = new Image();

image.id = 'c9a8375cc12a';

image
    .inspect()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));
    

System

Events System

system
    .events()
    .then(stream => {
        stream.on('data', data => console.log(JSON.parse(data)));
    })
    .catch(err => console.error(`ERRO: ${err}`));
    

Version System

const system = new System();

system
    .version()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));

Ping System

const system = new System();

system
    .ping()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));
    

Info System

const system = new System();

system
    .info()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));
    

DF System

const system = new System();

system
    .df()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));
    

Registry

Registry Catalog

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

let registryAuth = new RegistryAuth('user', 'password', 'hostname');

let host = new Host(registryAuth.serveraddress, 443)
host.protocol = 'https';
host.versionApi = 'v2'

const registry = new Registry(host, registryAuth);

registry
    .catalog()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));
    

Registry Tags

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

let registryAuth = new RegistryAuth('user', 'password', 'hostname');

let host = new Host(registryAuth.serveraddress, 443)
host.protocol = 'https';
host.versionApi = 'v2'

const registry = new Registry(host, registryAuth);

registry
    .tags()
    .then(console.log)
    .catch(err => console.error(`ERRO: ${err}`));