Skip to content

Latest commit

 

History

History
51 lines (40 loc) · 1.33 KB

File metadata and controls

51 lines (40 loc) · 1.33 KB
description Docker extension API reference
keywords Docker, extensions, sdk, API, reference
skip_read_time true

Interface: ExtensionHost

Properties

cli

Readonly cli: ExtensionCli

Executes a command in the host.

For example, execute the shipped binary kubectl -h command in the host:

await ddClient.extension.host.cli.exec("kubectl", ["-h"]);

Streams the output of the command executed in the backend container or in the host.

Provided the kubectl binary is shipped as part of your extension, you can spawn the kubectl -h command in the host:

await ddClient.extension.host.cli.exec("kubectl", ["-h"], {
           stream: {
             onOutput(data): void {
                 // As we can receive both `stdout` and `stderr`, we wrap them in a JSON object
                 JSON.stringify(
                   {
                     stdout: data.stdout,
                     stderr: data.stderr,
                   },
                   null,
                   "  "
                 );
             },
             onError(error: any): void {
               console.error(error);
             },
             onClose(exitCode: number): void {
               console.log("onClose with exit code " + exitCode);
             },
           },
         });