import type { ContainerConfig, ContainerInfo, ContainerStats, DiskUsage, DockerContainerInspect, DockerImageInspect, ImageInfo, ContainerName, ImageName, NetworkInfo, NetworkDriver, VolumeInfo, VolumeDriver, LsEntry } from '../types'; import Docker from 'dockerode'; import type { ConnectConfig } from 'ssh2'; /** Parse the output of "ls -l" command into an array of LsEntry */ export declare function parseLsLong(listing: string): LsEntry[]; export default class DockerManager { #private; protected installed: boolean; protected dockerVersion: string; protected needSudo: boolean; protected readonly log: ioBroker.Logger; protected readonly namespace: `${string}.${number}`; protected readonly dockerApi?: { host?: string; port?: number | string; protocol?: 'http' | 'https' | 'ssh'; ca?: string; cert?: string; key?: string; username?: string | undefined; headers?: { [name: string]: string; }; timeout?: number | undefined; version?: string | undefined; sshAuthAgent?: string | undefined; sshOptions?: ConnectConfig | undefined; }; constructor(options: { dockerApi?: { host?: string; port?: number | string; protocol?: 'http' | 'https'; ca?: string; cert?: string; key?: string; }; logger: ioBroker.Logger; namespace: `${string}.${number}`; }); /** Wait till the check if docker is installed and the daemon is running is ready */ isReady(): Promise; /** * Get information about the Docker daemon: is it running and which version * * @returns Object with a version and daemonRunning */ getDockerDaemonInfo(): Promise<{ version?: string; daemonRunning?: boolean; removeSupported?: boolean; driver: 'socket' | 'cli' | 'http' | 'https' | 'ssh'; }>; static checkDockerSocket(): Promise; static isDockerApiRunningOnPort(port: number, host?: string): Promise; protected init(): Promise; getDefaultContainerName(): string; containerGetRamAndCpuUsage(containerNameOrId: ContainerName): Promise; /** * Update the image if a newer version is available * * @param image Image name with tag * @param ignoreIfNotExist If true, do not throw error if image does not exist * @returns New image info if image was updated, null if no update was necessary */ imageUpdate(image: ImageName, ignoreIfNotExist?: boolean): Promise; /** Get disk usage information */ discUsage(): Promise; /** Pull an image from the registry */ imagePull(image: ImageName): Promise<{ stdout: string; stderr: string; images?: ImageInfo[]; }>; /** Autocomplete image names from Docker Hub */ imageNameAutocomplete(partialName: string): Promise<{ name: string; description: string; isOfficial: boolean; starCount: number; }[]>; static getDockerodeConfig(config: ContainerConfig): Docker.ContainerCreateOptions; /** * Create and start a container with the given configuration. No checks are done. */ containerRun(config: ContainerConfig): Promise<{ stdout: string; stderr: string; }>; /** * Create a container with the given configuration without starting it. No checks are done. */ containerCreate(config: ContainerConfig): Promise<{ stdout: string; stderr: string; }>; /** * Recreate a container * * This function checks if a container is running, stops it if necessary, * removes it and creates a new one with the given configuration. * The container is not started after creation. * * @param config new configuration * @returns stdout and stderr of the create command */ containerReCreate(config: ContainerConfig): Promise<{ stdout: string; stderr: string; }>; containerCreateCompose(compose: string): Promise<{ stdout: string; stderr: string; }>; /** List all images */ imageList(): Promise; /** Build an image from a Dockerfile */ imageBuild(dockerfilePath: string, tag: string): Promise<{ stdout: string; stderr: string; }>; /** Tag an image with a new tag */ imageTag(imageId: ImageName, newTag: string): Promise<{ stdout: string; stderr: string; }>; /** Remove an image */ imageRemove(imageId: ImageName): Promise<{ stdout: string; stderr: string; images?: ImageInfo[]; }>; static rodeInspect2DockerImageInspect(data: Docker.ImageInspectInfo): DockerImageInspect; /** Inspect an image */ imageInspect(imageId: ImageName): Promise; imagePrune(): Promise<{ stdout: string; stderr: string; }>; /** * Stop a container * * @param container Container name or ID */ containerStop(container: ContainerName): Promise<{ stdout: string; stderr: string; containers?: ContainerInfo[]; }>; /** * Start a container * * @param container Container name or ID */ containerStart(container: ContainerName): Promise<{ stdout: string; stderr: string; containers?: ContainerInfo[]; }>; /** * Restart a container * * This function restarts a container by its name or ID. * It accepts an optional timeout in seconds to wait before killing the container (default is 5 seconds). * * @param container Container name or ID * @param timeoutSeconds Timeout in seconds to wait before killing the container (default: 5) */ containerRestart(container?: ContainerName, timeoutSeconds?: number): Promise<{ stdout: string; stderr: string; }>; /** Find the IP address of a container, via which it can be reached from the host */ getIpOfContainer(containerName?: ContainerName): Promise; /** * Remove the container and if necessary, stop it first * * @param container Container name or ID */ containerRemove(container: ContainerName): Promise<{ stdout: string; stderr: string; containers?: ContainerInfo[]; }>; /** * List all containers * * @param all If true, list all containers. If false, the list only running containers. Default is true. */ containerList(all?: boolean): Promise; /** * Get the logs of a container * * @param containerNameOrId Container name or ID * @param options Options for logs * @param options.tail Number of lines to show from the end of the logs * @param options.follow If true, follow the logs (not implemented yet) */ containerLogs(containerNameOrId: ContainerName, options?: { tail?: number; follow?: boolean; }): Promise; static dockerodeInspect2DockerContainerInspect(data: Docker.ContainerInspectInfo): DockerContainerInspect; /** Inspect a container */ containerInspect(containerNameOrId: string): Promise; containerPrune(): Promise<{ stdout: string; stderr: string; }>; /** * Build a docker run command string from ContainerConfig */ static toDockerRun(config: ContainerConfig, create?: boolean): string; networkList(): Promise; networkCreate(name: string, driver?: NetworkDriver): Promise<{ stdout: string; stderr: string; networks?: NetworkInfo[]; }>; networkRemove(networkId: string): Promise<{ stdout: string; stderr: string; networks?: NetworkInfo[]; }>; networkPrune(): Promise<{ stdout: string; stderr: string; networks?: NetworkInfo[]; }>; /** List all volumes */ volumeList(): Promise; volumeCopyTo(volumeName: string, sourcePath: string): Promise<{ stdout: string; stderr: string; }>; /** List files in a volume */ volumeDir(volumeName: string, path?: string): Promise; /** Read a text file from a volume */ volumeFile(volumeName: string, filePath: string): Promise; /** * Create a volume * * @param name Volume name * @param driver Volume driver * @param volume Volume options (depends on a driver) */ volumeCreate(name: string, driver?: VolumeDriver, volume?: string): Promise<{ stdout: string; stderr: string; volumes?: VolumeInfo[]; }>; /** Remove a volume */ volumeRemove(volumeName: string): Promise<{ stdout: string; stderr: string; volumes?: VolumeInfo[]; }>; /** Prune unused volumes */ volumePrune(): Promise<{ stdout: string; stderr: string; volumes?: VolumeInfo[]; }>; /** Stop own containers if necessary */ destroy(): Promise; }