feat: initial commit
This commit is contained in:
124
docker/libraries/container.ts
Normal file
124
docker/libraries/container.ts
Normal file
@@ -0,0 +1,124 @@
|
||||
import { CreateExecOptions, Exec } from "./exec.ts";
|
||||
import { modem } from "./modem.ts";
|
||||
|
||||
export class Container {
|
||||
/**
|
||||
* Instantiate a docker container.
|
||||
*
|
||||
* @param id - The container ID.
|
||||
* @param warnings - Warnings encountered during the container creation.
|
||||
*/
|
||||
constructor(
|
||||
readonly id: string,
|
||||
readonly warnings: string[],
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Start the container.
|
||||
*
|
||||
* @see https://docs.docker.com/engine/api/v1.45/#tag/Container/operation/ContainerStart
|
||||
*
|
||||
* @param query.signal - Signal to send to the container as an integer or string (e.g. SIGINT).
|
||||
* @param query.t - An integer representing the number of seconds to wait before killing the container.
|
||||
*/
|
||||
async start(query: SignalQuery = {}) {
|
||||
await modem.post({ path: `/containers/${this.id}/start`, query });
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the container.
|
||||
*
|
||||
* @see https://docs.docker.com/engine/api/v1.45/#tag/Container/operation/ContainerStop
|
||||
*
|
||||
* @param query.signal - Signal to send to the container as an integer or string (e.g. SIGINT).
|
||||
* @param query.t - An integer representing the number of seconds to wait before killing the container.
|
||||
*/
|
||||
async stop(query: SignalQuery = {}) {
|
||||
await modem.post({ path: `/containers/${this.id}/stop`, query });
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the container.
|
||||
*
|
||||
* @see https://docs.docker.com/engine/api/v1.45/#tag/Container/operation/ContainerDelete
|
||||
*
|
||||
* @param query.v - Remove the volumes associated with the container.
|
||||
* @param query.force - Kill the container if it is running.
|
||||
* @param query.link - Remove the specified link and not the underlying container.
|
||||
*/
|
||||
async remove(query: { v?: boolean; force?: boolean; link?: boolean } = {}) {
|
||||
await modem.del({ path: `/containers/${this.id}`, query });
|
||||
}
|
||||
|
||||
/**
|
||||
* Return low-level information about a container.
|
||||
*
|
||||
* @see https://docs.docker.com/engine/api/v1.45/#tag/Container/operation/ContainerInspect
|
||||
*/
|
||||
async inspect() {
|
||||
return modem.get({ path: `/containers/${this.id}/json` });
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the logs of the container.
|
||||
*
|
||||
* @see https://docs.docker.com/engine/api/v1.45/#tag/Container/operation/ContainerLogs
|
||||
*
|
||||
* @param handler - Function to handle each line of the logs.
|
||||
*/
|
||||
async logs(handler: (line: string) => true | void) {
|
||||
const res = await modem.request({
|
||||
method: "GET",
|
||||
path: `/containers/${this.id}/logs`,
|
||||
query: {
|
||||
stdout: true,
|
||||
follow: true,
|
||||
tail: "all",
|
||||
},
|
||||
});
|
||||
for await (const chunk of res.stream) {
|
||||
if (handler(chunk) === true) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a command inside the running container.
|
||||
*
|
||||
* @see https://docs.docker.com/engine/api/v1.45/#tag/Exec/operation/ContainerExec
|
||||
*
|
||||
* @param cmd - Command to run.
|
||||
* @param opts - Options for the command.
|
||||
*/
|
||||
async exec(cmd: string | string[], opts: Partial<CreateExecOptions> = {}) {
|
||||
const { Id } = await modem.post<{ Id: string }>({
|
||||
path: `/containers/${this.id}/exec`,
|
||||
body: {
|
||||
...opts,
|
||||
Cmd: Array.isArray(cmd) ? cmd : [cmd],
|
||||
AttachStdout: true,
|
||||
AttachStderr: true,
|
||||
},
|
||||
});
|
||||
return new Exec(Id).start();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------------
|
||||
| Types
|
||||
|--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
type SignalQuery = {
|
||||
/**
|
||||
* Signal to send to the container as an integer or string (e.g. SIGINT).
|
||||
*/
|
||||
signal?: string;
|
||||
|
||||
/**
|
||||
* An integer representing the number of seconds to wait before killing the container.
|
||||
*/
|
||||
t?: number;
|
||||
};
|
||||
32
docker/libraries/docker.ts
Normal file
32
docker/libraries/docker.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { ContainerConfig } from "../types/container.ts";
|
||||
import { modem } from "./modem.ts";
|
||||
import { Container } from "./container.ts";
|
||||
import { Image } from "./image.ts";
|
||||
|
||||
export class Docker {
|
||||
/**
|
||||
* Create a new docker container.
|
||||
*
|
||||
* @see https://docs.docker.com/engine/api/v1.45/#tag/Container/operation/ContainerCreate
|
||||
*
|
||||
* @params config - The configuration for the container.
|
||||
* @params query - Query parameters.
|
||||
*/
|
||||
async createContainer(config: Partial<ContainerConfig>, query: Partial<{ name: string; platform: string }> = {}) {
|
||||
const { Id, Warnings } = await modem.post<{ Id: string; Warnings: string[] }>({
|
||||
path: "/containers/create",
|
||||
query,
|
||||
body: config,
|
||||
});
|
||||
return new Container(Id, Warnings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Pull an image from the docker registry.
|
||||
*
|
||||
* @param image - The image to pull.
|
||||
*/
|
||||
async pullImage(image: string) {
|
||||
await new Image().create({ fromImage: image });
|
||||
}
|
||||
}
|
||||
107
docker/libraries/exec.ts
Normal file
107
docker/libraries/exec.ts
Normal file
@@ -0,0 +1,107 @@
|
||||
import delay from "delay";
|
||||
|
||||
import { modem } from "./modem.ts";
|
||||
|
||||
export class Exec {
|
||||
constructor(readonly id: string) {}
|
||||
|
||||
/**
|
||||
* Starts the current exec instance. If detach is true, this endpoint
|
||||
* returns immediately after starting the command. Otherwise, it sets up an
|
||||
* interactive session with the command.
|
||||
*
|
||||
* @param body - Request body schema.
|
||||
*/
|
||||
async start(body: Partial<StartSchema> = {}) {
|
||||
await modem.post({ path: `/exec/${this.id}/start`, body });
|
||||
await this.#endSignal();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return low-level information about the exec instance.
|
||||
*/
|
||||
async inspect() {
|
||||
return modem.get<InspectResponse>({ path: `/exec/${this.id}/json` });
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------------
|
||||
| Utilities
|
||||
|--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
* Wait for the current exec instance to finish its execution by observing
|
||||
* its running state.
|
||||
*
|
||||
* [TODO] Introduce a timeout signal in case we want to add a treshold to the
|
||||
* running time.
|
||||
*/
|
||||
async #endSignal() {
|
||||
while (true) {
|
||||
const info = await this.inspect();
|
||||
if (info.Running === false) {
|
||||
break;
|
||||
}
|
||||
await delay(250);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------------
|
||||
| Types
|
||||
|--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
export type CreateExecOptions = {
|
||||
AttachStdin: boolean;
|
||||
AttachStdout: boolean;
|
||||
AttachStderr: boolean;
|
||||
ConsoleSize: [number, number];
|
||||
Tty: boolean;
|
||||
Env: string[];
|
||||
Cmd: string[];
|
||||
Privileged: boolean;
|
||||
User: string;
|
||||
WorkingDir: string;
|
||||
};
|
||||
|
||||
type StartSchema = {
|
||||
/**
|
||||
* Detach from the command.
|
||||
*/
|
||||
Detach: boolean;
|
||||
|
||||
/**
|
||||
* Allocate a pseudo-TTY.
|
||||
*/
|
||||
Tty: boolean;
|
||||
|
||||
/**
|
||||
* Initial console size, as an `[height, width]` array.
|
||||
*/
|
||||
ConsoleSize?: [number, number];
|
||||
};
|
||||
|
||||
type InspectResponse = {
|
||||
CanRemove: boolean;
|
||||
ContainerID: string;
|
||||
DetachKeys: string;
|
||||
ExitCode: number;
|
||||
ID: string;
|
||||
OpenStderr: boolean;
|
||||
OpenStdin: boolean;
|
||||
OpenStdout: boolean;
|
||||
ProcessConfig: ProcessConfig;
|
||||
Running: boolean;
|
||||
Pid: number;
|
||||
};
|
||||
|
||||
type ProcessConfig = {
|
||||
arguments: string[];
|
||||
entrypoint: string;
|
||||
privileged: boolean;
|
||||
tty: boolean;
|
||||
user: string;
|
||||
};
|
||||
155
docker/libraries/image.ts
Normal file
155
docker/libraries/image.ts
Normal file
@@ -0,0 +1,155 @@
|
||||
import { modem } from "./modem.ts";
|
||||
|
||||
export class Image {
|
||||
/**
|
||||
* Pull or import an image.
|
||||
*
|
||||
* @see https://docs.docker.com/engine/api/v1.45/#tag/Image/operation/ImageCreate
|
||||
*
|
||||
* @param query - The configuration for the image.
|
||||
*/
|
||||
async create(query: Partial<CreateImageOptions>) {
|
||||
if (query.fromImage !== undefined) {
|
||||
const hasImage = await this.inspect(query.fromImage);
|
||||
if (hasImage !== undefined) {
|
||||
return; // we already have this image
|
||||
}
|
||||
}
|
||||
const res = await modem.request({
|
||||
method: "POST",
|
||||
path: "/images/create",
|
||||
headers: {
|
||||
"Content-Type": "text/plain",
|
||||
},
|
||||
query,
|
||||
});
|
||||
res.close();
|
||||
if (res.status !== 200) {
|
||||
throw new Error("Docker Image > Failed to create new image");
|
||||
}
|
||||
}
|
||||
|
||||
async inspect(image: string): Promise<InspectImageResponse | undefined> {
|
||||
try {
|
||||
return await modem.get<InspectImageResponse>({ path: `/images/${image}/json` });
|
||||
} catch (_) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------------
|
||||
| Types
|
||||
|--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
type CreateImageOptions = {
|
||||
/**
|
||||
* Name of the image to pull. The name may include a tag or digest. This
|
||||
* parameter may only be used when pulling an image. The pull is cancelled if
|
||||
* the HTTP connection is closed.
|
||||
*/
|
||||
fromImage: string;
|
||||
};
|
||||
|
||||
type InspectImageResponse = {
|
||||
Id: string;
|
||||
RepoTags: string[];
|
||||
RepoDigests: string[];
|
||||
Parent: string;
|
||||
Comment: string;
|
||||
Created: string;
|
||||
Container: string;
|
||||
ContainerConfig: {
|
||||
Hostname: string;
|
||||
Domainname: string;
|
||||
User: string;
|
||||
AttachStdin: boolean;
|
||||
AttachStdout: boolean;
|
||||
AttachStderr: boolean;
|
||||
ExposedPorts: Record<string, any>;
|
||||
Tty: boolean;
|
||||
OpenStdin: boolean;
|
||||
StdinOnce: boolean;
|
||||
Env: string[];
|
||||
Cmd: string[];
|
||||
Healthcheck: {
|
||||
Test: string[];
|
||||
Interval: number;
|
||||
Timeout: number;
|
||||
Retries: number;
|
||||
StartPeriod: number;
|
||||
StartInterval: number;
|
||||
};
|
||||
ArgsEscaped: boolean;
|
||||
Image: string;
|
||||
Volumes: Record<string, any>;
|
||||
WorkingDir: string;
|
||||
Entrypoint: string[];
|
||||
NetworkDisabled: boolean;
|
||||
MacAddress: string;
|
||||
OnBuild: string[];
|
||||
Labels: Record<string, string>;
|
||||
StopSignal: string;
|
||||
StopTimeout: number;
|
||||
Shell: string[];
|
||||
};
|
||||
DockerVersion: string;
|
||||
Author: string;
|
||||
Config: {
|
||||
Hostname: string;
|
||||
Domainname: string;
|
||||
User: string;
|
||||
AttachStdin: boolean;
|
||||
AttachStdout: boolean;
|
||||
AttachStderr: boolean;
|
||||
ExposedPorts: Record<string, any>;
|
||||
Tty: boolean;
|
||||
OpenStdin: boolean;
|
||||
StdinOnce: boolean;
|
||||
Env: string[];
|
||||
Cmd: string[];
|
||||
Healthcheck: {
|
||||
Test: string[];
|
||||
Interval: number;
|
||||
Timeout: number;
|
||||
Retries: number;
|
||||
StartPeriod: number;
|
||||
StartInterval: number;
|
||||
};
|
||||
ArgsEscaped: boolean;
|
||||
Image: string;
|
||||
Volumes: Record<string, any>;
|
||||
WorkingDir: string;
|
||||
Entrypoint: string[];
|
||||
NetworkDisabled: boolean;
|
||||
MacAddress: string;
|
||||
OnBuild: string[];
|
||||
Labels: Record<string, string>;
|
||||
StopSignal: string;
|
||||
StopTimeout: number;
|
||||
Shell: string[];
|
||||
};
|
||||
Architecture: string;
|
||||
Variant: string;
|
||||
Os: string;
|
||||
OsVersion: string;
|
||||
Size: number;
|
||||
VirtualSize: number;
|
||||
GraphDriver: {
|
||||
Name: string;
|
||||
Data: {
|
||||
MergedDir: string;
|
||||
UpperDir: string;
|
||||
WorkDir: string;
|
||||
};
|
||||
};
|
||||
RootFS: {
|
||||
Type: string;
|
||||
Layers: string[];
|
||||
};
|
||||
Metadata: {
|
||||
LastTagTime: string;
|
||||
};
|
||||
};
|
||||
114
docker/libraries/modem.ts
Normal file
114
docker/libraries/modem.ts
Normal file
@@ -0,0 +1,114 @@
|
||||
import { Client, type Response } from "../../http/mod.ts";
|
||||
|
||||
class Modem {
|
||||
constructor(readonly options: Deno.ConnectOptions | Deno.UnixConnectOptions, readonly client = new Client(options)) {}
|
||||
|
||||
/**
|
||||
* Send a `POST` request to the Docker API.
|
||||
*
|
||||
* @param param.path - Path of the API endpoint.
|
||||
* @param param.query - Query parameters.
|
||||
* @param param.body - Request body.
|
||||
*/
|
||||
async post<T = Record<string, never>>({ path, query = {}, body }: RequestOptions): Promise<T> {
|
||||
return getParsedResponse<T>(await this.request({ method: "POST", path, query, body }));
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a `GET` request to the Docker API.
|
||||
*
|
||||
* @param param.path - Path of the API endpoint.
|
||||
* @param param.query - Query parameters.
|
||||
*/
|
||||
async get<T = Record<string, never>>({ path, query }: Omit<RequestOptions, "body">): Promise<T> {
|
||||
return getParsedResponse<T>(await this.request({ method: "GET", path, query }));
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a `DELETE` request to the Docker API.
|
||||
*
|
||||
* @param param.path - Path of the API endpoint.
|
||||
* @param param.query - Query parameters.
|
||||
*/
|
||||
async del<T = Record<string, never>>({ path, query }: Omit<RequestOptions, "body">): Promise<T> {
|
||||
return getParsedResponse<T>(await this.request({ method: "DELETE", path, query }));
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a fetch request to the Docker API.
|
||||
*
|
||||
* Note! When calling this method directly, ensure to call the .close() method on the response
|
||||
* or active connections may remain open causing dirty shutdown of services. Only when accessing
|
||||
* the .stream of the response through an async itterator is the connection automatically closed
|
||||
* when the itterator has completed.
|
||||
*
|
||||
* @param param.method - HTTP method to use.
|
||||
* @param param.path - Path of the API endpoint.
|
||||
* @param param.query - Query parameters.
|
||||
* @param param.body - Request body. _(Ignored for `GET` requests.)_
|
||||
* @param param.headers - Headers to send with the request.
|
||||
*/
|
||||
async request(
|
||||
{ method, path, query = {}, body, headers = {} }: { method: "POST" | "GET" | "DELETE" } & RequestOptions,
|
||||
): Promise<Response> {
|
||||
return this.client.fetch(`http://docker${path}${toSearchParams(query)}`, {
|
||||
method,
|
||||
body,
|
||||
headers,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const modem = new Modem({
|
||||
path: "/var/run/docker.sock",
|
||||
transport: "unix",
|
||||
});
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------------
|
||||
| Utilities
|
||||
|--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
function getParsedResponse<T>(res: Response): T {
|
||||
res.close();
|
||||
if (res.status >= 400) {
|
||||
const error = res.json;
|
||||
assertError(error);
|
||||
throw new Error(error.message);
|
||||
}
|
||||
if (res.status === 204 || res.status === 304) {
|
||||
return {} as T;
|
||||
}
|
||||
return res.json as T;
|
||||
}
|
||||
|
||||
function toSearchParams(query: Record<string, unknown>): string {
|
||||
if (Object.keys(query).length === 0) {
|
||||
return "";
|
||||
}
|
||||
const searchParams = new URLSearchParams();
|
||||
for (const [key, value] of Object.entries(query)) {
|
||||
searchParams.append(key, String(value));
|
||||
}
|
||||
return `?${searchParams.toString()}`;
|
||||
}
|
||||
|
||||
function assertError(error: unknown): asserts error is { message: string } {
|
||||
if (typeof error !== "object" || error === null || !("message" in error)) {
|
||||
throw new Error("Docker Modem > Could not parse error response.");
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------------
|
||||
| Types
|
||||
|--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
type RequestOptions = {
|
||||
path: string;
|
||||
headers?: RequestInit["headers"];
|
||||
query?: Record<string, unknown>;
|
||||
body?: Record<string, unknown>;
|
||||
};
|
||||
3
docker/mod.ts
Normal file
3
docker/mod.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { Docker } from "./libraries/docker.ts";
|
||||
|
||||
export const docker = new Docker();
|
||||
361
docker/types/container.ts
Normal file
361
docker/types/container.ts
Normal file
@@ -0,0 +1,361 @@
|
||||
export type ContainerConfig = {
|
||||
/**
|
||||
* The hostname to use for the container, as a valid RFC 1123 hostname.
|
||||
*/
|
||||
Hostname: string;
|
||||
|
||||
/**
|
||||
* The domain name to use for the container.
|
||||
*/
|
||||
Domainname: string;
|
||||
|
||||
/**
|
||||
* The user that commands are run as inside the container.
|
||||
*/
|
||||
User: string;
|
||||
|
||||
/**
|
||||
* Whether to attach to `stdin`.
|
||||
*/
|
||||
AttachStdin: boolean;
|
||||
|
||||
/**
|
||||
* Whether to attach to `stdout`.
|
||||
*/
|
||||
AttachStdout: boolean;
|
||||
|
||||
/**
|
||||
* Whether to attach to `stderr`.
|
||||
*/
|
||||
AttachStderr: boolean;
|
||||
|
||||
/**
|
||||
* An object mapping ports to an empty object in the form:
|
||||
* `{"<port>/<tcp|udp>": {}}`.
|
||||
* ```ts
|
||||
* {
|
||||
* ExposedPorts: {
|
||||
* "22/tcp": {},
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
ExposedPorts: Record<string, unknown>;
|
||||
|
||||
/**
|
||||
* Attach standard streams to a TTY, including `stdin` if it is not closed.
|
||||
*/
|
||||
Tty: boolean;
|
||||
|
||||
/**
|
||||
* Open `stdin`.
|
||||
*/
|
||||
OpenStdin: boolean;
|
||||
|
||||
/**
|
||||
* Close `stdin` after one attached client disconnects.
|
||||
*/
|
||||
StdinOnce: boolean;
|
||||
|
||||
/**
|
||||
* A list of environment variables to set inside the container in the form:
|
||||
* `["VAR=value", ...]`. A variable without `=` is removed from the environment,
|
||||
* rather than to have an empty value.
|
||||
*/
|
||||
Env: string[];
|
||||
|
||||
/**
|
||||
* Command to run specified as a string or an array of strings.
|
||||
*/
|
||||
Cmd: string[];
|
||||
|
||||
/**
|
||||
* A test to perform to check that the container is healthy.
|
||||
*/
|
||||
Healthcheck: HealthConfig;
|
||||
|
||||
/**
|
||||
* The name (or reference) of the image to use when creating the container, or
|
||||
* which was used when the container was created.
|
||||
*/
|
||||
Image: string;
|
||||
|
||||
/**
|
||||
* An object mapping mount point paths inside the container to empty objects.
|
||||
* ```ts
|
||||
* {
|
||||
* Volumes: {
|
||||
* "/volumes/data": {}
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
Volumes: Record<string, unknown>;
|
||||
|
||||
/**
|
||||
* The working directory for commands to run in.
|
||||
*/
|
||||
WorkingDir: string;
|
||||
|
||||
/**
|
||||
* The entry point for the container as a string or an array of strings.
|
||||
*
|
||||
* If the array consists of exactly one empty string (`[""]`) then the entry
|
||||
* point is reset to system default (i.e., the entry point used by docker
|
||||
* when there is no `ENTRYPOINT` instruction in the `Dockerfile`).
|
||||
*/
|
||||
Entrypoint: string[];
|
||||
|
||||
/**
|
||||
* Disable networking for the container.
|
||||
*/
|
||||
NetworkDisabled: boolean | null;
|
||||
|
||||
/**
|
||||
* `ONBUILD` metadata that were defined in the image's `Dockerfile`.
|
||||
*/
|
||||
OnBuild: string[] | null;
|
||||
|
||||
/**
|
||||
* User-defined key/value metadata.
|
||||
* ```ts
|
||||
* {
|
||||
* Labels: {
|
||||
* "com.example.vendor": "Acme",
|
||||
* "com.example.license": "GPL",
|
||||
* "com.example.version": "1.0"
|
||||
* }
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
Labels: Record<string, string>;
|
||||
|
||||
/**
|
||||
* Signal to stop a container as a string or unsigned integer.
|
||||
*/
|
||||
StopSignal: string;
|
||||
|
||||
/**
|
||||
* Timeout to stop a container in seconds.
|
||||
* Default: `10`
|
||||
*/
|
||||
StopTimeout: number;
|
||||
|
||||
/**
|
||||
* Shell for when `RUN`, `CMD`, and `ENTRYPOINT` uses a shell.
|
||||
*/
|
||||
Shell: string[];
|
||||
|
||||
/**
|
||||
* Container configuration that depends on the host we are running on
|
||||
*/
|
||||
HostConfig: Partial<HostConfig>;
|
||||
|
||||
/**
|
||||
* NetworkingConfig represents the container's networking configuration for
|
||||
* each of its interfaces. It is used for the networking configs specified
|
||||
* in the docker create and docker network connect commands.
|
||||
*/
|
||||
NetworkingConfig: Partial<NetworkingConfig>;
|
||||
};
|
||||
|
||||
type HealthConfig = {
|
||||
/**
|
||||
* The test to perform. Possible values are:
|
||||
* - `[]` inherit healthcheck from image or parent image
|
||||
* - `["NONE"]` disable healthcheck
|
||||
* - `["CMD", args...]` exec arguments directly
|
||||
* - `["CMD-SHELL", command]` run command with system's default shell
|
||||
*/
|
||||
Test: string[];
|
||||
|
||||
/**
|
||||
* The time to wait between checks in nanoseconds. It should be 0 or at least
|
||||
* 1_000_000 (1 ms). 0 means inherit
|
||||
*/
|
||||
Interval: number;
|
||||
|
||||
/**
|
||||
* The time to wait before considering the check to have hung. It should be 0
|
||||
* or at least 1_000_000 (1 ms). 0 means inherit.
|
||||
*/
|
||||
Timeout: number;
|
||||
|
||||
/**
|
||||
* The number of consecutive failures needed to consider a container as
|
||||
* unhealthy. 0 means inherit.
|
||||
*/
|
||||
Retries: number;
|
||||
|
||||
/**
|
||||
* Start period for the container to initialize before starting health-retries
|
||||
* countdown in nanoseconds. It should be 0 or at least 1_000_000 (1 ms). 0
|
||||
* means inherit.
|
||||
*/
|
||||
StartPeriod: number;
|
||||
|
||||
/**
|
||||
* The time to wait between checks in nanoseconds during the start period.
|
||||
* It should be 0 or at least 1_000_000 (1 ms). 0 means inherit.
|
||||
*/
|
||||
StartInterval: number;
|
||||
};
|
||||
|
||||
type HostConfig = {
|
||||
CpuShares: number;
|
||||
Memory: number;
|
||||
CgroupParent: string;
|
||||
BlkioWeight: number;
|
||||
BlkioWeightDevice: {
|
||||
Path: string;
|
||||
Integer: number;
|
||||
}[];
|
||||
BlkioDeviceReadBps: {
|
||||
Path: string;
|
||||
Rate: number;
|
||||
}[];
|
||||
BlkioDeviceWriteBps: {
|
||||
Path: string;
|
||||
Rate: number;
|
||||
}[];
|
||||
BlkioDeviceReadIOps: {
|
||||
Path: string;
|
||||
Rate: number;
|
||||
}[];
|
||||
BlkioDeviceWriteIOps: {
|
||||
Path: string;
|
||||
Rate: number;
|
||||
}[];
|
||||
CpuPeriod: number;
|
||||
CpuQuota: number;
|
||||
CpuRealtimePeriod: number;
|
||||
CpuRealtimeRuntime: number;
|
||||
CpusetCpus: string;
|
||||
CpusetMems: string;
|
||||
Devices: {
|
||||
PathOnHost: string;
|
||||
PathInContainer: string;
|
||||
CgroupPermissions: string;
|
||||
}[];
|
||||
DeviceCgroupRules: string[];
|
||||
DeviceRequests: {
|
||||
Driver: string;
|
||||
Count: number;
|
||||
DeviceIDs: string[];
|
||||
Capabilities: string[];
|
||||
Options: {
|
||||
Name: string;
|
||||
Value: string;
|
||||
}[];
|
||||
}[];
|
||||
KernelMemoryTCP: number;
|
||||
MemoryReservation: number;
|
||||
MemorySwap: number;
|
||||
MemorySwappiness: number;
|
||||
NanoCPUs: number;
|
||||
OomKillDisable: boolean;
|
||||
Init: boolean | null;
|
||||
PidsLimit: number;
|
||||
Ulimits: {
|
||||
Name: string;
|
||||
Soft: number;
|
||||
Hard: number;
|
||||
}[];
|
||||
CpuCount: number;
|
||||
CpuPercent: number;
|
||||
IOMaximumIOps: number;
|
||||
IOMaximumBandwidth: number;
|
||||
Binds: string[];
|
||||
ContainerIDFile: string;
|
||||
LogConfig: {
|
||||
Type: "json-file" | "syslog" | "journald" | "gelf" | "fluentd" | "awslogs" | "splunk" | "etwlogs" | "none";
|
||||
Config: Record<string, string>;
|
||||
};
|
||||
NetworkMode: string;
|
||||
PortBindings: Record<string, unknown>;
|
||||
RestartPolicy: {
|
||||
Name: "" | "no" | "always" | "unless-stopped" | "on-failure";
|
||||
MaximumRetryCount: number;
|
||||
};
|
||||
AutoRemove: boolean;
|
||||
VolumeDriver: string;
|
||||
VolumesFrom: string[];
|
||||
Mounts: {
|
||||
Target: string;
|
||||
Source: string;
|
||||
Type: "bind" | "volume" | "tmpfs" | "npipe" | "cluster";
|
||||
ReadOnly: boolean;
|
||||
Consistency: "default" | "consistent" | "cached" | "delegated";
|
||||
BindOptions: {
|
||||
Propagation: "private" | "rprivate" | "shared" | "rshared" | "slave" | "rslave";
|
||||
NonRecursive: boolean;
|
||||
CreateMountPoint: boolean;
|
||||
ReadOnlyNonRecursive: boolean;
|
||||
ReadOnlyForcedRecursive: boolean;
|
||||
};
|
||||
VolumeOptions: {
|
||||
NoCopy: boolean;
|
||||
Labels: Record<string, string>;
|
||||
DriverConfig: {
|
||||
Name: string;
|
||||
Options: Record<string, string>;
|
||||
};
|
||||
Subpath: string;
|
||||
};
|
||||
TmpfsOptions: {
|
||||
SizeBytes: number;
|
||||
Mode: number;
|
||||
};
|
||||
}[];
|
||||
ConsoleSize: number[];
|
||||
Annotations: Record<string, string>;
|
||||
CapAdd: string[];
|
||||
CapDrop: string[];
|
||||
CgroupnsMode: "host" | "private";
|
||||
Dns: string[];
|
||||
DnsOptions: string[];
|
||||
DnsSearch: string[];
|
||||
ExtraHosts: string[];
|
||||
GroupAdd: string[];
|
||||
IpcMode: "none" | "private" | "shareable" | "container:<name_or_id>" | "host";
|
||||
Cgroup: string;
|
||||
Links: string[];
|
||||
OomScoreAdj: number;
|
||||
PidMode: "host" | "container:<name_or_id>";
|
||||
Privileged: boolean;
|
||||
PublishAllPorts: boolean;
|
||||
ReadonlyRootfs: boolean;
|
||||
SecurityOpt: string[];
|
||||
StorageOpt: Record<string, string>;
|
||||
Tmpfs: Record<string, string>;
|
||||
UTSMode: string;
|
||||
UsernsMode: string;
|
||||
ShmSize: number;
|
||||
Sysctls: Record<string, string>;
|
||||
Runtime: string;
|
||||
MaskedPaths: string[];
|
||||
ReadonlyPaths: string[];
|
||||
};
|
||||
|
||||
type NetworkingConfig = {
|
||||
EndpointsConfig: Record<string, EndpointSettings>;
|
||||
};
|
||||
|
||||
type EndpointSettings = {
|
||||
IPAMConfig: {
|
||||
IPv4Address: string;
|
||||
IPv6Address: string;
|
||||
LinkLocalIPs: string[];
|
||||
};
|
||||
Links: string[];
|
||||
Aliases: string[];
|
||||
NetworkID: string;
|
||||
EndpointID: string;
|
||||
Gateway: string;
|
||||
IPAddress: string;
|
||||
IPPrefixLen: number;
|
||||
IPv6Gateway: string;
|
||||
GlobalIPv6Address: string;
|
||||
GlobalIPv6PrefixLen: number;
|
||||
MacAddress: string;
|
||||
};
|
||||
Reference in New Issue
Block a user