@@ -65,21 +65,47 @@ Streams the output as a result of the execution of a docker command.
65
65
Useful when you need to get the output as a stream or the output of the command is too long.
66
66
67
67
``` typescript linenums="1"
68
- await window . ddClient .docker .cli .exec (" logs" , [" -f" , " ..." ], {
68
+ await ddClient .docker .cli .exec (" logs" , [" -f" , " ..." ], {
69
69
stream: {
70
- onOutput(data : { stdout : string } | { stderr : string }) : void {
70
+ onOutput(data ) {
71
71
console .log (data .stdout );
72
72
},
73
- onError(error : any ) : void {
73
+ onError(error ) {
74
74
console .error (error );
75
75
},
76
- onClose(exitCode : number ) : void {
76
+ onClose(exitCode ) {
77
77
console .log (" onClose with exit code " + exitCode );
78
78
},
79
+ splitOutputLines: true ,
79
80
},
80
81
});
81
82
```
82
83
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
+
83
109
Use the [ Exec API reference] ( reference/interfaces/Exec.md ) for details about these methods
84
110
85
111
### Deprecated execution of Docker commands
0 commit comments