Skip to content

LockTech/docker-client-ts

Repository files navigation

🐳   Docker Engine API Client

(a) NodeJS client for the Docker Engine API, with support for TypeScript




Note
See the contributing section for details on generating a different version of the client.

Getting Started

Start by installing the client using your preferred package manager, below is an example of Yarn.

yarn add @locktech/docker-client

The client is configured to use Axios for making requests, providing support for connecting to a UNIX socket. This functionality can be used to connect directly to the host machine's Docker dameon. Because requests are being made against the socket and not an HTTP server, the baseURL can be any valid URL.

import { Api } from '@locktech/docker-client'

export const docker = new Api({
  baseURL: 'http://localhost',
  socketPath: '/var/run/docker.sock',
})

Once the API has been initalized, it can be used to make requests against the configured Docker Engine API.

const DoSomething = async () => {
  const containers = await docker.containers.containerList({ ... })

  for (const container of containers.data) {
    ...
  }
}

Contributing

This repository acts as a template for generating, building, and publishing a client for the Docker Engine API. This process is triggered when a new release is created, which will use the configured specification as a reference for generation. After being generated, the built package is published to the npm registry.

name: CI — Generate and Release

env:
  # Update the following to change the reference used for generating the client.
  DOCKER_ENGINE_API: https://docs.docker.com/engine/api/v1.41.yaml

...

Building Manually

The following steps will build the client locally, and is the same set of steps used by the repository's CI runner.

  1. git clone https://github.com/LockTech/docker-client-ts.git
  2. npm install
  3. npm run generate https://docs.docker.com/engine/api/vX.XX.yaml
    • Generate a client using the given specification as a reference.
    • You can get the published version via the release workflow.
  4. npm run build

License

This repository and the generated code is provided under the MIT license. The reference Swagger specification - used to generate the client - is licensed under Apache 2.0.

References