Skip to content

Commit a6c242b

Browse files
committed
Update documentation about exec streaming, mention splitOutputLines and add docker events sample
Signed-off-by: Guillaume Tardif <guillaume.tardif@gmail.com>
1 parent 7d70557 commit a6c242b

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

docs/dev/api/docker.md

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,47 @@ Streams the output as a result of the execution of a docker command.
6565
Useful when you need to get the output as a stream or the output of the command is too long.
6666

6767
```typescript linenums="1"
68-
await window.ddClient.docker.cli.exec("logs", ["-f", "..."], {
68+
await ddClient.docker.cli.exec("logs", ["-f", "..."], {
6969
stream: {
70-
onOutput(data: { stdout: string } | { stderr: string }): void {
70+
onOutput(data) {
7171
console.log(data.stdout);
7272
},
73-
onError(error: any): void {
73+
onError(error) {
7474
console.error(error);
7575
},
76-
onClose(exitCode: number): void {
76+
onClose(exitCode) {
7777
console.log("onClose with exit code " + exitCode);
7878
},
79+
splitOutputLines: true,
7980
},
8081
});
8182
```
8283

84+
This can also be useful to listen to docker events:
85+
86+
```typescript linenums="1"
87+
await ddClient.docker.cli.exec(
88+
"events",
89+
["--format", "{{ json . }}", "--filter", "container=my-container"],
90+
{
91+
stream: {
92+
onOutput(data) {
93+
if (data.stdout) {
94+
const event = JSON.parse(data.stdout);
95+
console.log(event);
96+
} else {
97+
console.log(data.stderr);
98+
}
99+
},
100+
onClose(exitCode) {
101+
console.log("onClose with exit code " + exitCode);
102+
},
103+
splitOutputLines: true,
104+
},
105+
}
106+
);
107+
```
108+
83109
Use the [Exec API reference](reference/interfaces/Exec.md) for details about these methods
84110

85111
### Deprecated execution of Docker commands

0 commit comments

Comments
 (0)