@dockstat/docker 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +4 -0
- package/dist/index.js.map +25 -0
- package/dist/types.d.ts +2442 -0
- package/package.json +5 -2
- package/src/docker.ts +0 -35
- package/src/environment.d.ts +0 -15
- package/src/index.ts +0 -9
- package/src/modules/_socket/index.ts +0 -106
- package/src/modules/base/index.ts +0 -30
- package/src/modules/base/types.ts +0 -17
- package/src/modules/container/index.ts +0 -384
- package/src/modules/container/types.ts +0 -673
- package/src/modules/distribution/index.ts +0 -14
- package/src/modules/distribution/types.ts +0 -24
- package/src/modules/exec/index.ts +0 -60
- package/src/modules/exec/types.ts +0 -64
- package/src/modules/images/index.ts +0 -220
- package/src/modules/images/types.ts +0 -686
- package/src/modules/networks/index.ts +0 -87
- package/src/modules/networks/types.ts +0 -258
- package/src/modules/nodes/index.ts +0 -48
- package/src/modules/nodes/types.ts +0 -69
- package/src/modules/plugins/index.ts +0 -128
- package/src/modules/plugins/types.ts +0 -114
- package/src/modules/secrets/index.ts +0 -5
- package/src/modules/secrets/types.ts +0 -0
- package/src/modules/volumes/index.ts +0 -65
- package/src/modules/volumes/types.ts +0 -197
- package/src/utils/env.ts +0 -48
- package/src/utils/error.ts +0 -23
- package/src/utils/request-options.ts +0 -68
- package/src/utils/response.ts +0 -31
- package/src/utils/url.ts +0 -48
package/package.json
CHANGED
|
@@ -6,11 +6,14 @@
|
|
|
6
6
|
"name": "ItsNik",
|
|
7
7
|
"url": "https://itsnik.de"
|
|
8
8
|
},
|
|
9
|
+
"exports": {
|
|
10
|
+
".": "./src/index.ts"
|
|
11
|
+
},
|
|
9
12
|
"keywords": [
|
|
10
13
|
"docker",
|
|
11
14
|
"bun"
|
|
12
15
|
],
|
|
13
|
-
"version": "0.1.
|
|
16
|
+
"version": "0.1.1",
|
|
14
17
|
"license": "MPL-2.0",
|
|
15
18
|
"repository": {
|
|
16
19
|
"directory": "packages/bun-docker",
|
|
@@ -27,7 +30,7 @@
|
|
|
27
30
|
"typescript": "^5"
|
|
28
31
|
},
|
|
29
32
|
"files": [
|
|
30
|
-
"
|
|
33
|
+
"dist",
|
|
31
34
|
"README.md",
|
|
32
35
|
"tsconfig.json"
|
|
33
36
|
],
|
package/src/docker.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { BaseModule } from "./modules/base"
|
|
2
|
-
import type { ConnectionConfig } from "./modules/base/types"
|
|
3
|
-
import { ContainerModule } from "./modules/container"
|
|
4
|
-
import { DistributionModule } from "./modules/distribution"
|
|
5
|
-
import { ExecModule } from "./modules/exec"
|
|
6
|
-
import { ImagesModule } from "./modules/images"
|
|
7
|
-
import { NetworksModule } from "./modules/networks"
|
|
8
|
-
import { NodesModule } from "./modules/nodes"
|
|
9
|
-
import { VolumeModule } from "./modules/volumes"
|
|
10
|
-
|
|
11
|
-
export class Docker {
|
|
12
|
-
public readonly containers: ContainerModule
|
|
13
|
-
public readonly images: ImagesModule
|
|
14
|
-
public readonly networks: NetworksModule
|
|
15
|
-
public readonly volumes: VolumeModule
|
|
16
|
-
public readonly exec: ExecModule
|
|
17
|
-
public readonly distribution: DistributionModule
|
|
18
|
-
public readonly nodes: NodesModule
|
|
19
|
-
|
|
20
|
-
constructor(private config: ConnectionConfig) {
|
|
21
|
-
this.containers = new ContainerModule(config)
|
|
22
|
-
this.images = new ImagesModule(config)
|
|
23
|
-
this.networks = new NetworksModule(config)
|
|
24
|
-
this.volumes = new VolumeModule(config)
|
|
25
|
-
this.exec = new ExecModule(config)
|
|
26
|
-
this.distribution = new DistributionModule(config)
|
|
27
|
-
this.nodes = new NodesModule(config)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async ping(): Promise<boolean> {
|
|
31
|
-
const requester = new BaseModule(this.config)
|
|
32
|
-
const res = await requester.request("/_ping", "GET")
|
|
33
|
-
return res.ok
|
|
34
|
-
}
|
|
35
|
-
}
|
package/src/environment.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
declare global {
|
|
2
|
-
namespace NodeJS {
|
|
3
|
-
interface ProcessEnv {
|
|
4
|
-
DOCKER_SOCKET: "/var/run/docker.sock" | string
|
|
5
|
-
ENABLE_API?: string
|
|
6
|
-
API_KEYS?: string
|
|
7
|
-
API_PORT?: string
|
|
8
|
-
KEY_FILE?: "./key.pem"
|
|
9
|
-
CERT_FILE?: "./cert.pem"
|
|
10
|
-
CA_FILE?: "./ca.pem"
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export {}
|
package/src/index.ts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import type { ReadableStreamDefaultReader } from "node:stream/web"
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* WebSocket-like interface for Docker container attach
|
|
5
|
-
* Uses the attach endpoint with stream wrapping for compatibility with Unix sockets
|
|
6
|
-
*
|
|
7
|
-
* @note Currently supports read-only operations (receiving stdout/stderr). Full WebSocket
|
|
8
|
-
* protocol support with bidirectional communication is planned for future versions.
|
|
9
|
-
*/
|
|
10
|
-
export class DockerWebSocket {
|
|
11
|
-
private static readonly CONNECTING = 0
|
|
12
|
-
private static readonly OPEN = 1
|
|
13
|
-
private static readonly CLOSING = 2
|
|
14
|
-
private static readonly CLOSED = 3
|
|
15
|
-
|
|
16
|
-
private readyStateValue: number = DockerWebSocket.CONNECTING
|
|
17
|
-
private listeners: Map<string, Array<(event: unknown) => void>> = new Map()
|
|
18
|
-
private reader: ReadableStreamDefaultReader | null = null
|
|
19
|
-
|
|
20
|
-
addEventListener(type: string, listener: (event: unknown) => void) {
|
|
21
|
-
if (!this.listeners.has(type)) {
|
|
22
|
-
this.listeners.set(type, [])
|
|
23
|
-
}
|
|
24
|
-
this.listeners.get(type)?.push(listener)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
removeEventListener(type: string, listener: (event: unknown) => void) {
|
|
28
|
-
const typeListeners = this.listeners.get(type)
|
|
29
|
-
if (typeListeners) {
|
|
30
|
-
const index = typeListeners.indexOf(listener)
|
|
31
|
-
if (index > -1) {
|
|
32
|
-
typeListeners.splice(index, 1)
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
async attach(response: Response) {
|
|
38
|
-
if (!response.body) {
|
|
39
|
-
this.emit("error", new Error("Response has no body"))
|
|
40
|
-
this.readyStateValue = DockerWebSocket.CLOSED
|
|
41
|
-
this.emit("close", {})
|
|
42
|
-
return
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
this.reader = response.body.getReader()
|
|
46
|
-
this.readyStateValue = DockerWebSocket.OPEN
|
|
47
|
-
this.emit("open", {})
|
|
48
|
-
|
|
49
|
-
try {
|
|
50
|
-
while (this.readyStateValue === DockerWebSocket.OPEN) {
|
|
51
|
-
const { done, value } = await this.reader.read()
|
|
52
|
-
if (done) break
|
|
53
|
-
|
|
54
|
-
// Decode the chunk to string
|
|
55
|
-
const text = new TextDecoder().decode(value)
|
|
56
|
-
this.emit("message", { data: text })
|
|
57
|
-
}
|
|
58
|
-
} catch (error) {
|
|
59
|
-
if (this.readyStateValue !== DockerWebSocket.CLOSING) {
|
|
60
|
-
this.emit("error", error)
|
|
61
|
-
}
|
|
62
|
-
} finally {
|
|
63
|
-
this.readyStateValue = DockerWebSocket.CLOSED
|
|
64
|
-
this.emit("close", {})
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
close() {
|
|
69
|
-
if (this.readyStateValue === DockerWebSocket.CLOSED) return
|
|
70
|
-
|
|
71
|
-
this.readyStateValue = DockerWebSocket.CLOSING
|
|
72
|
-
|
|
73
|
-
if (this.reader) {
|
|
74
|
-
this.reader.cancel().catch(() => {})
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
this.readyStateValue = DockerWebSocket.CLOSED
|
|
78
|
-
this.emit("close", {})
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
get CONNECTING() {
|
|
82
|
-
return DockerWebSocket.CONNECTING
|
|
83
|
-
}
|
|
84
|
-
get OPEN() {
|
|
85
|
-
return DockerWebSocket.OPEN
|
|
86
|
-
}
|
|
87
|
-
get CLOSING() {
|
|
88
|
-
return DockerWebSocket.CLOSING
|
|
89
|
-
}
|
|
90
|
-
get CLOSED() {
|
|
91
|
-
return DockerWebSocket.CLOSED
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
get readyState() {
|
|
95
|
-
return this.readyStateValue
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
private emit(type: string, event: unknown) {
|
|
99
|
-
const listeners = this.listeners.get(type)
|
|
100
|
-
if (listeners) {
|
|
101
|
-
for (const listener of listeners) {
|
|
102
|
-
listener(event)
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { BodyInit, HeadersInit } from "bun"
|
|
2
|
-
import { prepareRequestOptions } from "../../utils/request-options"
|
|
3
|
-
import { handleDockerResponse } from "../../utils/response"
|
|
4
|
-
import { buildDockerUrl, buildQueryString } from "../../utils/url"
|
|
5
|
-
import { DockerWebSocket } from "../_socket"
|
|
6
|
-
import type { ConnectionConfig, HttpMethod } from "./types"
|
|
7
|
-
|
|
8
|
-
export class BaseModule {
|
|
9
|
-
constructor(private config: ConnectionConfig) {}
|
|
10
|
-
|
|
11
|
-
protected ws = new DockerWebSocket()
|
|
12
|
-
|
|
13
|
-
async request(
|
|
14
|
-
path: string,
|
|
15
|
-
method: HttpMethod = "GET",
|
|
16
|
-
body?: BodyInit | object,
|
|
17
|
-
headers?: HeadersInit,
|
|
18
|
-
params?: object
|
|
19
|
-
) {
|
|
20
|
-
const dockerApiVersion = this.config.dockerAPIVersion || "1.54"
|
|
21
|
-
const query = buildQueryString(params)
|
|
22
|
-
const url = buildDockerUrl(this.config, path, query, dockerApiVersion)
|
|
23
|
-
|
|
24
|
-
const options = prepareRequestOptions(this.config, method, body, headers, url)
|
|
25
|
-
|
|
26
|
-
const response = await fetch(url, options)
|
|
27
|
-
|
|
28
|
-
return handleDockerResponse(response, path, dockerApiVersion, params)
|
|
29
|
-
}
|
|
30
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { TLSOptions } from "bun"
|
|
2
|
-
|
|
3
|
-
export type ConnectionMode = "unix" | "tcp"
|
|
4
|
-
|
|
5
|
-
export interface ConnectionConfig {
|
|
6
|
-
mode: ConnectionMode
|
|
7
|
-
// For Unix: the file path
|
|
8
|
-
socketPath?: string
|
|
9
|
-
// For TCP: the full base URL (e.g., http://192.168.1.50:2375)
|
|
10
|
-
baseUrl?: string
|
|
11
|
-
// TLS options (used for TCP or TLS-secured Unix sockets)
|
|
12
|
-
tls?: TLSOptions
|
|
13
|
-
// The docker API version
|
|
14
|
-
dockerAPIVersion?: string
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export type HttpMethod = "GET" | "POST" | "PUT" | "DELETE" | "HEAD"
|
|
@@ -1,384 +0,0 @@
|
|
|
1
|
-
import type { BodyInit } from "bun"
|
|
2
|
-
import { BaseModule } from "../base"
|
|
3
|
-
import type { DockerWebSocket } from "../_socket"
|
|
4
|
-
import type {
|
|
5
|
-
ArchiveInfo,
|
|
6
|
-
AttachOptions,
|
|
7
|
-
ContainerConfig,
|
|
8
|
-
ContainerCreateResponse,
|
|
9
|
-
ContainerInspectResponse,
|
|
10
|
-
ContainerPruneResponse,
|
|
11
|
-
ContainerStatsResponse,
|
|
12
|
-
ContainerSummary,
|
|
13
|
-
ContainerTopResponse,
|
|
14
|
-
ContainerUpdateResponse,
|
|
15
|
-
ContainerWaitResponse,
|
|
16
|
-
CreateContainerOptions,
|
|
17
|
-
ExecCreateOptions,
|
|
18
|
-
ExecCreateResponse,
|
|
19
|
-
ExecInspectResponse,
|
|
20
|
-
ExecStartOptions,
|
|
21
|
-
FilesystemChange,
|
|
22
|
-
ListContainersOptions,
|
|
23
|
-
LogsOptions,
|
|
24
|
-
PruneContainersOptions,
|
|
25
|
-
StatsOptions,
|
|
26
|
-
UpdateContainerOptions,
|
|
27
|
-
WaitCondition,
|
|
28
|
-
} from "./types"
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Container Module - handles all Docker container operations
|
|
32
|
-
*/
|
|
33
|
-
export class ContainerModule extends BaseModule {
|
|
34
|
-
/**
|
|
35
|
-
* List containers
|
|
36
|
-
* @param options - List options
|
|
37
|
-
* @returns Array of container summaries
|
|
38
|
-
*/
|
|
39
|
-
async list(options?: ListContainersOptions): Promise<ContainerSummary[]> {
|
|
40
|
-
const path = `/containers/json`
|
|
41
|
-
const res = await this.request(path, "GET", undefined, undefined, options)
|
|
42
|
-
return (await res.json()) as ContainerSummary[]
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Create a container
|
|
47
|
-
* @param config - Container configuration
|
|
48
|
-
* @param options - Create options
|
|
49
|
-
* @returns Container create response with ID
|
|
50
|
-
*/
|
|
51
|
-
async create(config: ContainerConfig, options?: CreateContainerOptions): Promise<ContainerCreateResponse> {
|
|
52
|
-
const path = `/containers/create`
|
|
53
|
-
const res = await this.request(path, "POST", config, undefined, options)
|
|
54
|
-
return (await res.json()) as ContainerCreateResponse
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Inspect a container
|
|
59
|
-
* @param id - Container ID or name
|
|
60
|
-
* @param size - Return container size information
|
|
61
|
-
* @returns Detailed container information
|
|
62
|
-
*/
|
|
63
|
-
async inspect(id: string, size: boolean = false): Promise<ContainerInspectResponse> {
|
|
64
|
-
const res = await this.request(`/containers/${id}/json`, "GET", undefined, undefined, {
|
|
65
|
-
size: size,
|
|
66
|
-
})
|
|
67
|
-
return (await res.json()) as ContainerInspectResponse
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* Start a container
|
|
72
|
-
* @param id - Container ID or name
|
|
73
|
-
* @param detachKeys - Override the key sequence for detaching
|
|
74
|
-
*/
|
|
75
|
-
async start(id: string, detachKeys?: string): Promise<void> {
|
|
76
|
-
await this.request(`/containers/${id}/start`, "POST", undefined, undefined, {
|
|
77
|
-
detachKeys: detachKeys,
|
|
78
|
-
})
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Stop a container
|
|
83
|
-
* @param id - Container ID or name
|
|
84
|
-
* @param t - Number of seconds to wait before killing the container
|
|
85
|
-
*/
|
|
86
|
-
async stop(id: string, t?: number): Promise<void> {
|
|
87
|
-
await this.request(`/containers/${id}/stop`, "POST", undefined, undefined, { t: t })
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Restart a container
|
|
92
|
-
* @param id - Container ID or name
|
|
93
|
-
* @param t - Number of seconds to wait before killing the container
|
|
94
|
-
*/
|
|
95
|
-
async restart(id: string, t?: number): Promise<void> {
|
|
96
|
-
await this.request(`/containers/${id}/restart`, "POST", undefined, undefined, { t: t })
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Kill a container
|
|
101
|
-
* @param id - Container ID or name
|
|
102
|
-
* @param signal - Signal to send to the container
|
|
103
|
-
*/
|
|
104
|
-
async kill(id: string, signal?: string): Promise<void> {
|
|
105
|
-
await this.request(`/containers/${id}/kill`, "POST", undefined, undefined, { signal: signal })
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Remove a container
|
|
110
|
-
* @param id - Container ID or name
|
|
111
|
-
* @param v - Remove anonymous volumes associated with the container
|
|
112
|
-
* @param force - Force removal of running containers
|
|
113
|
-
* @param link - Remove the specified link associated with the container
|
|
114
|
-
*/
|
|
115
|
-
async remove(
|
|
116
|
-
id: string,
|
|
117
|
-
v: boolean = false,
|
|
118
|
-
force: boolean = false,
|
|
119
|
-
link: boolean = false
|
|
120
|
-
): Promise<void> {
|
|
121
|
-
await this.request(`/containers/${id}`, "DELETE", undefined, undefined, {
|
|
122
|
-
v: v,
|
|
123
|
-
force: force,
|
|
124
|
-
link: link,
|
|
125
|
-
})
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Rename a container
|
|
130
|
-
* @param id - Container ID or name
|
|
131
|
-
* @param name - New name for the container
|
|
132
|
-
*/
|
|
133
|
-
async rename(id: string, name: string): Promise<void> {
|
|
134
|
-
await this.request(`/containers/${id}/rename`, "POST", undefined, undefined, { name: name })
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Pause a container
|
|
139
|
-
* @param id - Container ID or
|
|
140
|
-
name
|
|
141
|
-
*/
|
|
142
|
-
async pause(id: string): Promise<void> {
|
|
143
|
-
await this.request(`/containers/${id}/pause`, "POST")
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* Unpause a container
|
|
148
|
-
* @param id - Container ID or name
|
|
149
|
-
*/
|
|
150
|
-
async unpause(id: string): Promise<void> {
|
|
151
|
-
await this.request(`/containers/${id}/unpause`, "POST")
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Wait for a container
|
|
156
|
-
* @param id - Container ID or name
|
|
157
|
-
* @param condition - Wait until condition is met
|
|
158
|
-
* @returns Container wait response with exit status
|
|
159
|
-
*/
|
|
160
|
-
async wait(id: string, condition?: WaitCondition): Promise<ContainerWaitResponse> {
|
|
161
|
-
const res = await this.request(`/containers/${id}/wait`, "POST", undefined, undefined, {
|
|
162
|
-
condition: condition,
|
|
163
|
-
})
|
|
164
|
-
return (await res.json()) as ContainerWaitResponse
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* List processes running inside a container
|
|
169
|
-
* @param id - Container ID or name
|
|
170
|
-
* @param ps_args - Arguments for ps command
|
|
171
|
-
* @returns Top processes response
|
|
172
|
-
*/
|
|
173
|
-
async top(id: string, ps_args?: string): Promise<ContainerTopResponse> {
|
|
174
|
-
const res = await this.request(`/containers/${id}/top`, "GET", undefined, undefined, {
|
|
175
|
-
ps_args: encodeURIComponent(ps_args || ""),
|
|
176
|
-
})
|
|
177
|
-
return (await res.json()) as ContainerTopResponse
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Get container logs
|
|
182
|
-
* @param id - Container ID or name
|
|
183
|
-
* @param options - Log options
|
|
184
|
-
* @returns Log stream
|
|
185
|
-
*/
|
|
186
|
-
async logs(id: string, options?: LogsOptions): Promise<Response> {
|
|
187
|
-
return await this.request(`/containers/${id}/logs`, "GET", undefined, undefined, options)
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
/**
|
|
191
|
-
* Get container resource usage statistics
|
|
192
|
-
* @param id - Container ID or name
|
|
193
|
-
* @param options - Stats options
|
|
194
|
-
* @returns Container stats response
|
|
195
|
-
*/
|
|
196
|
-
async stats(id: string, options?: StatsOptions): Promise<ContainerStatsResponse | Response> {
|
|
197
|
-
const res = await this.request(`/containers/${id}/stats`, "GET", undefined, undefined, options)
|
|
198
|
-
|
|
199
|
-
if (options?.stream) {
|
|
200
|
-
return res
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
return (await res.json()) as ContainerStatsResponse
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Get changes on container filesystem
|
|
208
|
-
* @param id - Container ID or name
|
|
209
|
-
* @returns Array of filesystem changes
|
|
210
|
-
*/
|
|
211
|
-
async changes(id: string): Promise<FilesystemChange[]> {
|
|
212
|
-
const res = await this.request(`/containers/${id}/changes`, "GET")
|
|
213
|
-
return (await res.json()) as FilesystemChange[]
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Export a container
|
|
218
|
-
* @param id - Container ID or name
|
|
219
|
-
* @returns Exported container archive
|
|
220
|
-
*/
|
|
221
|
-
async export(id: string): Promise<Response> {
|
|
222
|
-
return await this.request(`/containers/${id}/export`, "GET")
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Update container configuration
|
|
227
|
-
* @param id - Container ID or name
|
|
228
|
-
* @param options - Update options
|
|
229
|
-
* @returns Update response with warnings
|
|
230
|
-
*/
|
|
231
|
-
async update(id: string, options: UpdateContainerOptions): Promise<ContainerUpdateResponse> {
|
|
232
|
-
const res = await this.request(`/containers/${id}/update`, "POST", options)
|
|
233
|
-
return res.json() as ContainerUpdateResponse
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Resize container TTY
|
|
238
|
-
* @param id - Container ID or name
|
|
239
|
-
* @param h - Height of the TTY session
|
|
240
|
-
* @param w - Width of the TTY session
|
|
241
|
-
*/
|
|
242
|
-
async resize(id: string, h: number, w: number): Promise<void> {
|
|
243
|
-
await this.request(`/containers/${id}/resize`, "POST", undefined, undefined, { h: h, w: w })
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Attach to a container
|
|
248
|
-
* @param id - Container ID or name
|
|
249
|
-
* @param options - Attach options
|
|
250
|
-
* @returns Attach connection
|
|
251
|
-
*/
|
|
252
|
-
async attach(id: string, options?: AttachOptions): Promise<Response> {
|
|
253
|
-
return await this.request(`/containers/${id}/attach`, "POST", undefined, undefined, options)
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Attach to a container via WebSocket
|
|
258
|
-
* @param id - Container ID or name
|
|
259
|
-
* @param options - Attach options
|
|
260
|
-
* @returns WebSocket-like connection
|
|
261
|
-
* @note Uses the attach endpoint with stream wrapping for compatibility with Unix sockets
|
|
262
|
-
*/
|
|
263
|
-
async attachWebSocket(id: string, options?: AttachOptions): Promise<DockerWebSocket> {
|
|
264
|
-
const response = await this.request(
|
|
265
|
-
`/containers/${id}/attach`,
|
|
266
|
-
"POST",
|
|
267
|
-
undefined,
|
|
268
|
-
undefined,
|
|
269
|
-
options
|
|
270
|
-
)
|
|
271
|
-
|
|
272
|
-
this.ws.attach(response)
|
|
273
|
-
|
|
274
|
-
return this.ws
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* Get an archive of a filesystem resource in a container
|
|
279
|
-
* @param id - Container ID or name
|
|
280
|
-
* @param path - Resource path in the container
|
|
281
|
-
* @returns Archive stream
|
|
282
|
-
*/
|
|
283
|
-
|
|
284
|
-
async getArchive(id: string, path: string): Promise<Response> {
|
|
285
|
-
return await this.request(`/containers/${id}/archive`, "GET", undefined, undefined, {
|
|
286
|
-
path: path,
|
|
287
|
-
})
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Check if a file exists in a container
|
|
292
|
-
* @param id - Container ID or name
|
|
293
|
-
* @param path - Resource path in the container
|
|
294
|
-
* @returns Archive info or null
|
|
295
|
-
*/
|
|
296
|
-
async archiveInfo(id: string, path: string): Promise<ArchiveInfo | null> {
|
|
297
|
-
const res = await this.request(`/containers/${id}/archive`, "HEAD", undefined, undefined, {
|
|
298
|
-
path: path,
|
|
299
|
-
})
|
|
300
|
-
|
|
301
|
-
const dockerContentType = res.headers.get("X-Docker-Container-Path-Stat")
|
|
302
|
-
if (!dockerContentType) return null
|
|
303
|
-
|
|
304
|
-
try {
|
|
305
|
-
return JSON.parse(dockerContentType)
|
|
306
|
-
} catch {
|
|
307
|
-
return null
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
/**
|
|
312
|
-
* Extract an archive of files or folders to a directory in the container
|
|
313
|
-
* @param id - Container ID or name
|
|
314
|
-
* @param path - Path to extract to
|
|
315
|
-
* @param archive - Archive to extract
|
|
316
|
-
* @param noOverwriteDirNonDir - If true, will not overwrite a dir with a non-dir
|
|
317
|
-
* @param copyUIDGID - If set to true, copy ownership from archive to target
|
|
318
|
-
*/
|
|
319
|
-
async putArchive(
|
|
320
|
-
id: string,
|
|
321
|
-
path: string,
|
|
322
|
-
archive: BodyInit,
|
|
323
|
-
noOverwriteDirNonDir: boolean = false,
|
|
324
|
-
copyUIDGID: boolean = false
|
|
325
|
-
): Promise<void> {
|
|
326
|
-
await this.request(`/containers/${id}/archive`, "PUT", archive, undefined, {
|
|
327
|
-
path: path,
|
|
328
|
-
noOverwriteDirNonDir: noOverwriteDirNonDir,
|
|
329
|
-
copyUIDGID: copyUIDGID,
|
|
330
|
-
})
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* Create an exec instance
|
|
335
|
-
* @param id - Container ID or name
|
|
336
|
-
* @param options - Exec create options
|
|
337
|
-
* @returns Exec create response with exec ID
|
|
338
|
-
*/
|
|
339
|
-
async execCreate(id: string, options: ExecCreateOptions): Promise<ExecCreateResponse> {
|
|
340
|
-
const res = await this.request(`/containers/${id}/exec`, "POST", options)
|
|
341
|
-
return (await res.json()) as ExecCreateResponse
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
/**
|
|
345
|
-
* Start an exec instance
|
|
346
|
-
* @param id - Exec ID
|
|
347
|
-
* @param options - Exec start options
|
|
348
|
-
* @returns Exec stream
|
|
349
|
-
*/
|
|
350
|
-
async execStart(id: string, options?: ExecStartOptions): Promise<Response> {
|
|
351
|
-
const res = await this.request(`/exec/${id}/start`, "POST", undefined, undefined,options)
|
|
352
|
-
return res
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* Inspect an exec instance
|
|
357
|
-
* @param id - Exec ID
|
|
358
|
-
* @returns Exec inspect response
|
|
359
|
-
*/
|
|
360
|
-
async execInspect(id: string): Promise<ExecInspectResponse> {
|
|
361
|
-
const res = await this.request(`/exec/${id}/json`, "GET")
|
|
362
|
-
return (await res.json()) as ExecInspectResponse
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
/**
|
|
366
|
-
* Resize an exec TTY
|
|
367
|
-
* @param id - Exec ID
|
|
368
|
-
* @param h - Height of the TTY session
|
|
369
|
-
* @param w - Width of the TTY session
|
|
370
|
-
*/
|
|
371
|
-
async execResize(id: string, h: number, w: number): Promise<void> {
|
|
372
|
-
await this.request(`/exec/${id}/resize`, "POST", undefined, undefined, { h: h, w: w })
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
/**
|
|
376
|
-
* Delete stopped containers
|
|
377
|
-
* @param options - Prune options
|
|
378
|
-
* @returns Prune response with deleted containers and reclaimed space
|
|
379
|
-
*/
|
|
380
|
-
async prune(options?: PruneContainersOptions): Promise<ContainerPruneResponse> {
|
|
381
|
-
const res = await this.request(`/containers/prune`, "POST", undefined, undefined, options)
|
|
382
|
-
return (await res.json()) as ContainerPruneResponse
|
|
383
|
-
}
|
|
384
|
-
}
|