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-api-ts

v0.2.2

Published

A comprehensive TypeScript client for interacting with the Docker Engine API.

Downloads

388

Readme

Docker API TypeScript

docker-api-ts is an open-source TypeScript package that provides a comprehensive client for interacting with the Docker Engine API. This package includes various services to manage Docker containers, images, networks, volumes, and more.

Features

  • Container Management: Create, inspect, start, stop, and remove containers.
  • Image Management: Pull, tag, and remove Docker images.
  • Service Management: Create, update, and remove services in Docker Swarm mode.
  • System Operations: Get Docker system information and manage system-wide settings.
  • Execution Management: Run commands inside running containers.
  • Volume Management: Create, inspect, and remove Docker volumes.
  • Network Management: Create, inspect, and remove Docker networks.
  • Plugin Management: Install, enable, disable, and remove Docker plugins.
  • Node Management: Manage nodes in Docker Swarm.
  • Swarm Management: Initialize, join, and leave Docker Swarm.
  • Task Management: Inspect tasks in Docker Swarm.
  • Secret Management: Create, inspect, and remove Docker secrets.
  • Config Management: Create, inspect, and remove Docker configs.

Installation

Install the package using npm for Node.js users:

npm install docker-api-ts
# OR JSR
npx jsr add @rainypixel/docker-api-ts

For Deno users, you can import the module directly from the URL:

# ONLY JSR allowed
deno add @rainypixel/docker-api-ts
import Docker from '@rainypixel/docker-api-ts';

Usage

Here is an example of how to use the Docker API TypeScript client:

// Node.JS
import Docker from 'docker-api-ts';
// Deno
import Docker from '@rainypixel/docker-api-ts';

// Initialize the Docker client
const docker = new Docker('/var/run/docker.sock', null);

// List all containers
const containers = await docker.containers.containerList();
console.log(containers.body)

// Pull an image
const data = await docker.images.imageCreate({ fromImage: 'alpine', tag: 'latest' });
console.log(data.status);

// Create a new container
const data = await docker.containers.containerCreate({
  body: {
    Image: 'alpine:latest',
    Cmd: ['echo', 'hello world'],
  },
});
if (data.body?.Id) {
  await docker.containers.containerStart({ id: data.body.Id });
}

Connecting via TCP

You can also connect to the Docker daemon via TCP. Note that TCP TLS support is not ready yet and will be available in the next version.

Example

// Node.JS
import Docker from 'docker-api-ts';
// Deno
import Docker from '@rainypixel/docker-api-ts';

// Initialize the Docker client with TCP
const docker = new Docker({ host: '127.0.0.1', port: 2375, transport: 'tcp' }, null);

// List all containers
const containers = await docker.containers.containerList();
console.log(containers.body)

API Reference

Docker

The main class to interact with Docker services.

Constructor

new Docker(connectSetting: string | Deno.ConnectOptions, auth: RegistryAuthentication | null = null)
  • connectSetting: Connection settings as a string (if unix), or object if TCP (e.g., /var/run/docker.sock or { host: '127.0.0.1', port: 2375, transport: 'tcp' }).
  • auth: Optional authentication settings for Docker registry.

Services

  • containers: Instance of ContainerService to manage Docker containers.
  • images: Instance of ImageService to manage Docker images.
  • services: Instance of ServiceService to manage Docker services.
  • system: Instance of SystemService to manage Docker system operations.
  • exec: Instance of ExecService to run commands in containers.
  • volume: Instance of VolumeService to manage Docker volumes.
  • network: Instance of NetworkService to manage Docker networks.
  • plugin: Instance of PluginService to manage Docker plugins.
  • node: Instance of NodeService to manage Docker Swarm nodes.
  • swarm: Instance of SwarmService to manage Docker Swarm operations.
  • task: Instance of TaskService to inspect Docker Swarm tasks.
  • secret: Instance of SecretService to manage Docker secrets.
  • config: Instance of ConfigService to manage Docker configs.

Contributing

We welcome contributions! Please see the CONTRIBUTING.md for details on how to get started.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Incoming features

  • Add unit tests for each service in the package. (Priority: [Medium])
  • Write detailed examples for each service in the API reference section. (Priority: [Low])
  • Add TLS support. (Priority: [High])