Package Exports
- docker-client
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (docker-client) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
docker-client
What is it
This project generates and publishes an npm package containing:
- a whatwg-fetch based client for the Docker REST API
- TypeScript definitions for this client
The client and its type definitions are automatically generated from the Docker API swagger specification in https://github.com/moby/moby using https://github.com/swagger-api/swagger-codegen (specifically the typescript-fetch
language target).
Usage
Install
npm install --save docker-client
Import
import { ImageApi } from "docker-client";
const api = new ImageApi(); // API instance is lightweight to construct and stateless
// With no options, connects to localhost. Use type information to understand options.
api.imageList().then(list => console.log(list)); // List images
Use
The type definitions and Docker's own API documentation should help you explore the API and guide you in using it.
Gotchas
Most Docker instances with the remote API enabled will be using transport level security (TLS). This means you need a special set of certificates to communicate with the REST API. E.g. Docker hosts created with docker-machine
use TLS by default.
Fortunately, the generated client allows you to supply a bespoke implementation of fetch
, allowing you to point to the relevant certs. As an example, here is how you might connect to a Docker instance created with docker-machine create --driver virtualbox foo
:
import * as { FetchAPI, ImageApi } from "docker-client";
import * as https from "https";
import * as fs from "fs";
import nodeFetch from "node-fetch";
const agent = new https.Agent({
cert: fs.readFileSync("D:\\vms\\docker\\machines\\foo\\cert.pem"),
ca: fs.readFileSync("D:\\vms\\docker\\machines\\foo\\ca.pem"),
key: fs.readFileSync("D:\\vms\\docker\\machines\\foo\\key.pem")
});
const fetch: FetchAPI = (url, init) => nodeFetch(url, { ...init, agent });
const api = new ImageApi({ basePath: "https://1.2.3.4:2376" }, undefined, fetch);
api.imageList().then(list => console.log(list));