接口: DockerDesktopClient

Docker Desktop API客户端的v0和v1接口的混合体,出于向后兼容的原因提供。除非您正在使用旧版扩展,否则请使用v1类型。

属性

backend

Readonly 后端: undefined | BackendV0

window.ddClient.backend 对象可用于与扩展元数据中 vm 部分定义的后端进行通信。 客户端已经连接到后端。

警告

它将在未来的版本中被移除。请使用 extension 代替。

继承自

Docker桌面客户端V0.后端


extension

Readonly 扩展: Extension

ddClient.extension 对象可用于与扩展元数据中 vm 部分定义的后端进行通信。 客户端已经连接到后端。

继承自

DockerDesktopClientV1.extension


desktopUI

Readonly 桌面用户界面: DesktopUI

继承自

Docker桌面客户端V1.桌面用户界面


host

Readonly 主机: Host

继承自

Docker桌面客户端V1.主机


docker

Readonly docker: Docker

继承自

DockerDesktopClientV1.docker

容器方法

listContainers

listContainers(options): Promise<unknown>

获取正在运行的容器列表(与docker ps相同)。

默认情况下,这不会列出已停止的容器。 您可以使用选项 {"all": true} 来列出所有正在运行和已停止的容器。

const containers = await window.ddClient.listContainers();

警告

它将在未来的版本中被移除。请使用 listContainers 代替。

参数

NameTypeDescription
optionsnever(Optional). A JSON like { "all": true, "limit": 10, "size": true, "filters": JSON.stringify({ status: ["exited"] }), } For more information about the different properties see Docker API 端点文档.

返回

Promise<unknown>

继承自

DockerDesktopClientV0.listContainers


图像方法

listImages

listImages(options): Promise<unknown>

获取图像列表

const images = await window.ddClient.listImages();

警告

它将在未来的版本中被移除。请使用 listImages 代替。

参数

NameTypeDescription
optionsnever(Optional). A JSON like { "all": true, "filters": JSON.stringify({ dangling: ["true"] }), "digests": true } For more information about the different properties see Docker API 端点文档.

返回

Promise<unknown>

继承自

DockerDesktopClientV0.listImages


navigateToContainers(): void

导航到 Docker Desktop 中的容器窗口。

window.ddClient.navigateToContainers();

警告

它将在未来的版本中被移除。请使用 viewContainers 代替。

返回

void

继承自

DockerDesktopClientV0.navigateToContainers


navigateToContainer(id): Promise<any>

导航到 Docker Desktop 中的容器窗口。

await window.ddClient.navigateToContainer(id);

警告

它将在未来的版本中被移除。

参数

NameTypeDescription
idstringThe full container id, e.g. 46b57e400d801762e9e115734bf902a2450d89669d85881058a46136520aca28. You can use the --no-trunc flag as part of the docker ps command to display the full container id.

返回

Promise<any>

如果容器不存在,则承诺失败。

继承自

DockerDesktopClientV0.navigateToContainer


navigateToContainerLogs(id): Promise<any>

导航到 Docker Desktop 中的容器日志窗口。

await window.ddClient.navigateToContainerLogs(id);

警告

它将在未来的版本中被移除。

参数

NameTypeDescription
idstringThe full container id, e.g. 46b57e400d801762e9e115734bf902a2450d89669d85881058a46136520aca28. You can use the --no-trunc flag as part of the docker ps command to display the full container id.

返回

Promise<any>

如果容器不存在,则承诺失败。

继承自

DockerDesktopClientV0.navigateToContainerLogs


navigateToContainerInspect(id): Promise<any>

导航到Docker Desktop中的容器检查窗口。

await window.ddClient.navigateToContainerInspect(id);

警告

它将在未来的版本中被移除。

参数

NameTypeDescription
idstringThe full container id, e.g. 46b57e400d801762e9e115734bf902a2450d89669d85881058a46136520aca28. You can use the --no-trunc flag as part of the docker ps command to display the full container id.

返回

Promise<any>

如果容器不存在,则承诺失败。

继承自

DockerDesktopClientV0.navigateToContainerInspect


navigateToContainerStats(id): Promise<any>

导航到容器统计信息以查看CPU、内存、磁盘读/写和网络I/O使用情况。

await window.ddClient.navigateToContainerStats(id);

警告

它将在未来的版本中被移除。

参数

NameTypeDescription
idstringThe full container id, e.g. 46b57e400d801762e9e115734bf902a2450d89669d85881058a46136520aca28. You can use the --no-trunc flag as part of the docker ps command to display the full container id.

返回

Promise<any>

如果容器不存在,则承诺失败。

继承自

DockerDesktopClientV0.navigateToContainerStats


navigateToImages(): void

导航到 Docker Desktop 中的镜像窗口。

await window.ddClient.navigateToImages(id);

警告

它将在未来的版本中被移除。请使用 viewImages 代替。

返回

void

继承自

DockerDesktopClientV0.navigateToImages


navigateToImage(id, tag): Promise<any>

导航到Docker Desktop中由idtag引用的特定镜像。 在此导航路线中,您可以找到镜像层、命令、创建时间和大小。

await window.ddClient.navigateToImage(id, tag);

警告

它将在未来的版本中被移除。请使用 viewImage 代替。

参数

NameTypeDescription
idstringThe full image id (including sha), e.g. sha256:34ab3ae068572f4e85c448b4035e6be5e19cc41f69606535cd4d768a63432673.
tagstringThe tag of the image, e.g. latest, 0.0.1, etc.

返回

Promise<any>

如果容器不存在,则承诺失败。

继承自

DockerDesktopClientV0.navigateToImage


navigateToVolumes(): void

导航到 Docker Desktop 中的卷窗口。

await window.ddClient.navigateToVolumes();

警告

它将在未来的版本中被移除。请使用 viewVolumes 代替。

返回

void

继承自

DockerDesktopClientV0.navigateToVolumes


navigateToVolume(volume): void

在Docker Desktop中导航到特定卷。

window.ddClient.navigateToVolume(volume);

警告

它将在未来的版本中被移除。请使用 viewVolume 代替。

参数

NameTypeDescription
volumestringThe name of the volume, e.g. my-volume.

返回

void

继承自

DockerDesktopClientV0.navigateToVolume


navigateToDevEnvironments(): void

导航到 Docker Desktop 中的 Dev Environments 窗口。

window.ddClient.navigateToDevEnvironments();

警告

它将在未来的版本中被移除。请使用 viewDevEnvironments 代替。

返回

void

继承自

DockerDesktopClientV0.navigateToDevEnvironments


其他方法

execHostCmd

execHostCmd(cmd): Promise< ExecResultV0>

您可以在扩展元数据的主机部分中运行定义的二进制文件。

window.ddClient.execHostCmd(`cliShippedOnHost xxx`).then((cmdResult: any) => {
 console.log(cmdResult);
});

警告

它将在未来的版本中被移除。请使用 exec 代替。

参数

NameTypeDescription
cmdstringThe command to be executed.

返回

Promise< ExecResultV0>

继承自

DockerDesktopClientV0.execHostCmd


spawnHostCmd

spawnHostCmd(cmd, args, callback): void

在您的主机上调用扩展二进制文件并获取输出流。

window.ddClient.spawnHostCmd(
  `cliShippedOnHost`,
  [`arg1`, `arg2`],
  (data: any, err: any) => {
    console.log(data.stdout, data.stderr);
    // Once the command exits we get the status code
    if (data.code) {
      console.log(data.code);
    }
  }
);

警告

它将在未来的版本中被移除。请使用 exec 代替。

参数

NameTypeDescription
cmdstringThe command to be executed.
argsstring[]The arguments of the command to execute.
callback(data: any, error: any) => voidThe callback function where to listen from the command output data and errors.

返回

void

继承自

DockerDesktopClientV0.spawnHostCmd


execDockerCmd

execDockerCmd(cmd, ...args): Promise< ExecResultV0>

你也可以直接执行Docker二进制文件。

const output = await window.ddClient.execDockerCmd("info");

警告

它将在未来的版本中被移除。请使用 exec 代替。

参数

NameTypeDescription
cmdstringThe command to execute.
...argsstring[]The arguments of the command to execute.

返回

Promise< ExecResultV0>

结果将包含执行命令的标准输出和标准错误:

{
  "stderr": "...",
  "stdout": "..."
}

为了方便起见,命令结果对象还具有根据输出格式轻松解析它的方法:

  • output.lines(): string[] 分割输出行。
  • output.parseJsonObject(): any 解析一个格式良好的JSON输出。
  • output.parseJsonLines(): any[] 将每个输出行解析为JSON对象。

如果命令的输出太长,或者你需要将输出作为流获取,你可以使用

  • spawnDockerCmd 函数:
window.ddClient.spawnDockerCmd("logs", ["-f", "..."], (data, error) => {
  console.log(data.stdout);
});

继承自

DockerDesktopClientV0.execDockerCmd


spawnDockerCmd

spawnDockerCmd(cmd, args, callback): void

警告

它将在未来的版本中被移除。请使用 exec 代替。

参数

NameType
cmdstring
argsstring[]
callback(data: any, error: any) => void

返回

void

继承自

DockerDesktopClientV0.spawnDockerCmd


openExternal

openExternal(url): void

使用系统默认浏览器打开外部URL。

window.ddClient.openExternal("https://docker.com");

警告

它将在未来的版本中被移除。请改用 openExternal

参数

NameTypeDescription
urlstringThe URL the browser opens (must have the protocol http or https).

返回

void

继承自

DockerDesktopClientV0.openExternal


Toast 方法

toastSuccess

toastSuccess(msg): void

显示一个成功类型的提示消息。

window.ddClient.toastSuccess("message");

警告

它将在未来的版本中被移除。请使用 success 代替。

参数

NameTypeDescription
msgstringThe message to display in the toast.

返回

void

继承自

DockerDesktopClientV0.toastSuccess


toastWarning

toastWarning(msg): void

显示一个警告类型的提示消息。

window.ddClient.toastWarning("message");

警告

它将在未来的版本中被移除。请使用 warning 代替。

参数

NameTypeDescription
msgstringThe message to display in the toast.

返回

void

继承自

DockerDesktopClientV0.toastWarning


toastError

toastError(msg): void

显示一个错误类型的提示消息。

window.ddClient.toastError("message");

警告

它将在未来的版本中被移除。请使用 error 代替。

参数

NameTypeDescription
msgstringThe message to display in the toast.

返回

void

继承自

DockerDesktopClientV0.toastError