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

@onreza/docker-api-typescript

v0.5.1-0

Published

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

Downloads

22

Readme

Docker API TypeScript

docker-api-typescript 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 from NPM:

npm install @onreza/docker-api-typescript
yarn add @onreza/docker-api-typescript
pnpm add @onreza/docker-api-typescript
bun add @onreza/docker-api-typescript

By default, the package will work in Auto mode. You can change it manually:

// Auto Mode BUN or NodeJS
import Docker from '@onreza/docker-api-typescript';

// Manual Mode - NodeJS
import Docker from '@onreza/docker-api-typescript/node';

// Manual Mode - Bun
import Docker from '@onreza/docker-api-typescript/bun';

Usage

Example Usage

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

import Docker from '@onreza/docker-api-typescript';

// Initialize the Docker client
const docker = new Docker({ socketPath: '/var/run/docker.sock' });
//OR
const docker = new Docker({ endpoint: '127.0.0.1', port: 2375 });

// List all containers
const request = docker.containers.containerList();
const justResponse = await request();
const justData = await justResponse.json();
console.log(justData)

// Pull an image
const request = docker.images.imageCreate({ fromImage: 'alpine', tag: 'latest' });

const myHandler = (chunk) => {
  console.log(chunk);
}

const partResponse = await request(myHandler);

Authorizing to the Docker Registry

You can authorize to a Docker registry using the RegistryAuthentication class:

import { RegistryAuthentication } from '@onreza/docker-api-typescript';

const MyRegistry = new RegistryAuthentication({
  username: 'pepega',
  password: 'qwe123',
  serveraddress: 'some.cool.registry',
});

const docker = new Docker({
  endpoint: '127.0.0.1',
  port: 1337,
  registryAuthentication: MyRegistry,
});

API Reference

DockerClient

The DockerClient class provides methods for interacting with the Docker Engine.

request Method

public async request<T = unknown>(
  options: ConnectRequestProperties
): (callback?: ChunkedCallback) => Promise<void> | Promise<DockerResponse<T>>;
  • options: An object of type ConnectRequestProperties, specifying the request configuration.
  • Returns: A function that accepts an optional callback of type ChunkedCallback. If a callback is provided, the function returns a Promise<void> for handling chunked data. If no callback is provided, it returns a Promise<DockerResponse<T>> with the expected response type T.

RegistryAuthentication

The RegistryAuthentication class is used to manage Docker registry authentication credentials.

Constructor

new RegistryAuthentication({
  username: string,
  password: string,
  serveraddress: string,
})
  • username: The username for the Docker registry.
  • password: The password for the Docker registry.
  • serveraddress: The server address of the 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])