Interface: Docker

Interface: Docker

Docker Desktop 확장 SDK의 Docker 인터페이스예요. Docker CLI를 직접 호출하거나 실행 중인 컨테이너·이미지 목록을 가져오는 등 Docker 데몬 기능에 접근해요.

출처: 문서

본문

Interface: Docker

Since

0.2.0

속성

cli

Readonly cli: DockerCommandDockerCommand)

You can also directly execute the Docker binary.

const output = await ddClient.docker.cli.exec("volume", [
  "ls",
  "--filter",
  "dangling=true"
]);

Output:

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

For convenience, the command result object also has methods to easily parse it depending on output format. See ExecResultExecResult) instead.

Streams the output as a result of the execution of a Docker command. It is useful when the output of the command is too long, or you need to get the output as a stream.

await ddClient.docker.cli.exec("logs", ["-f", "..."], {
  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);
    },
  },
});

메서드

listContainers

listContainers(options?): Promise<unknown>

Get the list of running containers (same as docker ps).

By default, this will not list stopped containers. You can use the option {"all": true} to list all the running and stopped containers.

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

파라미터

Name | Type | Description options? | any | (Optional). A JSON like { "all": true, "limit": 10, "size": true, "filters": JSON.stringify({ status: ["exited"] }), } For more information about the different properties see the Docker API endpoint documentationthe Docker API endpoint documentation).

반환값

Promise<unknown>

listImages

listImages(options?): Promise<unknown>

Get the list of local container images

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

파라미터

Name | Type | Description options? | any | (Optional). A JSON like { "all": true, "filters": JSON.stringify({ dangling: ["true"] }), "digests": true * } For more information about the different properties see the Docker API endpoint documentationthe Docker API endpoint documentation).

반환값

Promise<unknown>

더 알아보기