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 🙏

© 2024 – Pkg Stats / Ryan Hefner

docker-engine

v0.6.0

Published

Node Docker Engine API Client Driven By Swagger

Downloads

28

Readme

docker-engine

A Docker Engine API client for Node, driven at run-time by Docker's Swagger definition.

Usage

To use docker-engine do:

const client = await dockerEngine()

This will connect to the Docker API using the default values (for example, /var/run/docker.sock to connect).

Connecting to a Docker Swarm on AWS

To use an SSH tunnel to connect to a swarm that has been set up using the Docker for AWS instructions, use config like the following:

const client = await dockerEngine({
  username: 'docker',
  privateKey: require('fs').readFileSync(__dirname + '/docker-swarm.pem', 'utf8'),
  host: 'ec2-54-183-237-159.us-west.compute-1.amazonaws.com',
  socketPath: '/var/run/docker.sock'
})

To output logging information on tunnel connections set the DEBUG environment variable:

DEBUG=docker-engine:tunnel \
DOCKER_AWS=ec2-54-183-237-159.us-west.compute-1.amazonaws.com \
  tap test/test.js

Why?

There are a number of excellent modules that allow you to connect to the Docker Engine API, but each of them caused me a problem in different ways. Whilst looking at making changes to these modules I realised that all a Docker API client needed was to use the Swagger file that Docker provides.

harbor-master: Has a minor issue with some endpoints. I investigated how to fix this and discovered that the API endpoint definitions use Joi; since Swagger files are maintained by Docker themselves, I felt that this was the wrong way to go.

dockerode: Dockerode also takes the approach of maintaining 'by hand' the connections between itself and the Docker API definitions. An example is the code required to implement the 'inspect container' endpoint. As with harbor-master I felt that this part of the module should be driven by the Swagger file.

docker-client: This module is driven the Swagger file. It's not dynamic--the client is generated with a code-generator that uses the Swagger file as input--but it would have been fine for my purposes. However, I was completely unable to get it to work with my local Docker Swarm. That's almost certain to be my fault, but I couldn't wait any longer, so had to move on. Note that because the client is generated it will be aligned with a specific version, whilst an approach that uses the Swagger file at run-time could be more dynamic.

Our Approach

Key to the approach we've taken here is:

  • to use the Swagger file as a single source of truth to drive the creation of the client. And more specifically, to do this at run-time so that the same module can be used for any version of the Docker API, without needing to be continually updated;
  • to use ES6 proxies to allow the client methods to be wrapped and so present different kinds of interfaces to developers. This makes it very easy to present harbor-master- or docker-client-compatible interfaces that still benefit from being Swagger-driven.