@apiclient.xyz/docker
Version:
Provides easy communication with Docker remote API from Node.js, with TypeScript support.
202 lines (201 loc) • 6.45 kB
TypeScript
import * as plugins from './plugins.js';
import * as interfaces from './interfaces/index.js';
import { DockerContainer } from './classes.container.js';
import { DockerNetwork } from './classes.network.js';
import { DockerService } from './classes.service.js';
import { DockerSecret } from './classes.secret.js';
import { DockerImage } from './classes.image.js';
export interface IAuthData {
serveraddress: string;
username: string;
password: string;
}
export interface IDockerHostConstructorOptions {
socketPath?: string;
imageStoreDir?: string;
}
export interface IHijackedStreamingResponse {
stream: plugins.stream.Duplex;
close: () => Promise<void>;
statusCode: number;
headers: plugins.http.IncomingHttpHeaders;
}
export declare class DockerHost {
options: IDockerHostConstructorOptions;
/**
* the path where the docker sock can be found
*/
socketPath: string;
private registryToken;
private imageStore;
smartBucket: plugins.smartbucket.SmartBucket;
/**
* the constructor to instantiate a new docker sock instance
* @param pathArg
*/
constructor(optionsArg: IDockerHostConstructorOptions);
start(): Promise<void>;
stop(): Promise<void>;
/**
* Ping the Docker daemon to check if it's running and accessible
* @returns Promise that resolves if Docker is available, rejects otherwise
* @throws Error if Docker ping fails
*/
ping(): Promise<void>;
/**
* Get Docker daemon version information
* @returns Version info including Docker version, API version, OS, architecture, etc.
*/
getVersion(): Promise<{
Version: string;
ApiVersion: string;
MinAPIVersion?: string;
GitCommit: string;
GoVersion: string;
Os: string;
Arch: string;
KernelVersion: string;
BuildTime?: string;
}>;
/**
* authenticate against a registry
* @param userArg
* @param passArg
*/
auth(authData: IAuthData): Promise<void>;
/**
* gets the token from the .docker/config.json file for GitLab registry
*/
getAuthTokenFromDockerConfig(registryUrlArg: string): Promise<void>;
/**
* Lists all networks
*/
listNetworks(): Promise<DockerNetwork[]>;
/**
* Gets a network by name
*/
getNetworkByName(networkNameArg: string): Promise<DockerNetwork | undefined>;
/**
* Creates a network
*/
createNetwork(descriptor: interfaces.INetworkCreationDescriptor): Promise<DockerNetwork>;
/**
* Lists all containers
*/
listContainers(): Promise<DockerContainer[]>;
/**
* Gets a container by ID
* Returns undefined if container does not exist
*/
getContainerById(containerId: string): Promise<DockerContainer | undefined>;
/**
* Creates a container
*/
createContainer(descriptor: interfaces.IContainerCreationDescriptor): Promise<DockerContainer>;
/**
* Lists all services
*/
listServices(): Promise<DockerService[]>;
/**
* Gets a service by name
*/
getServiceByName(serviceName: string): Promise<DockerService>;
/**
* Creates a service
*/
createService(descriptor: interfaces.IServiceCreationDescriptor): Promise<DockerService>;
/**
* Lists all images
*/
listImages(): Promise<DockerImage[]>;
/**
* Gets an image by name
*/
getImageByName(imageNameArg: string): Promise<DockerImage | undefined>;
/**
* Creates an image from a registry
*/
createImageFromRegistry(descriptor: interfaces.IImageCreationDescriptor): Promise<DockerImage>;
/**
* Creates an image from a tar stream
*/
createImageFromTarStream(tarStream: plugins.smartstream.stream.Readable, descriptor: interfaces.IImageCreationDescriptor): Promise<DockerImage>;
/**
* Prune unused images
* @param options Optional filters (dangling, until, label)
* @returns Object with deleted images and space reclaimed
*/
pruneImages(options?: {
dangling?: boolean;
filters?: Record<string, string[]>;
}): Promise<{
ImagesDeleted: Array<{
Untagged?: string;
Deleted?: string;
}>;
SpaceReclaimed: number;
}>;
/**
* Builds an image from a Dockerfile
*/
buildImage(imageTag: string): Promise<void>;
/**
* Lists all secrets
*/
listSecrets(): Promise<DockerSecret[]>;
/**
* Gets a secret by name
*/
getSecretByName(secretName: string): Promise<DockerSecret | undefined>;
/**
* Gets a secret by ID
*/
getSecretById(secretId: string): Promise<DockerSecret | undefined>;
/**
* Creates a secret
*/
createSecret(descriptor: interfaces.ISecretCreationDescriptor): Promise<DockerSecret>;
/**
* Stores an image in the local image store
*/
storeImage(imageName: string, tarStream: plugins.smartstream.stream.Readable): Promise<void>;
/**
* Retrieves an image from the local image store
*/
retrieveImage(imageName: string): Promise<plugins.smartstream.stream.Readable>;
/**
*
*/
getEventObservable(): Promise<plugins.rxjs.Observable<any>>;
/**
* activates docker swarm
*/
activateSwarm(addvertisementIpArg?: string): Promise<void>;
/**
* fire a request
*/
request(methodArg: string, routeArg: string, dataArg?: {}): Promise<{
statusCode: any;
body: any;
headers: any;
}>;
requestStreaming(methodArg: string, routeArg: string, readStream?: plugins.smartstream.stream.Readable, jsonData?: any): Promise<plugins.smartstream.stream.Readable | {
statusCode: number;
body: string;
headers: any;
}>;
requestHijackedStreaming(methodArg: string, routeArg: string, jsonData?: Record<string, unknown>): Promise<IHijackedStreamingResponse>;
private requestHijackedStreamingOverRawSocket;
private requestHijackedStreamingOverDenoUnixSocket;
private getNodeRequestOptions;
private createDuplexForHijackedResponse;
private createDuplexForRawSocket;
private createDuplexForDenoConn;
private parseRawHttpResponseHeaders;
private collectErrorResponse;
/**
* add s3 storage
* @param optionsArg
*/
addS3Storage(optionsArg: plugins.tsclass.storage.IS3Descriptor): Promise<void>;
}