Open chillcaw opened 1 year ago
Not sure if this a bug or I'm missing something here.
I'm copying a python file over and running it, but the Stream from Container::exec never seems to return None. When I run through docker exec it'll run once and exit.
Container::exec
None
docker exec
# sample.py my_var = 123 print(my_var) print(124) print(125) print(126)
// main.rs #[tokio::main] async fn main() { // There is more code here, but it all works so far // ... println!("Running Exec"); let options = ExecContainerOptions::builder() .cmd(vec!["python", "/opt/sample.py"]) .attach_stdout(true) .attach_stderr(true) .build(); while let Some(exec_result) = docker .containers() .get(&container_id) .exec(&options) .next() .await { match exec_result { Ok(chunk) => { print_chunk(chunk); } Err(e) => eprintln!("Error: {}", e), } } } fn print_chunk(chunk: TtyChunk) { match chunk { TtyChunk::StdOut(bytes) => println!("Stdout: {}", from_utf8(&bytes).unwrap()), TtyChunk::StdErr(bytes) => eprintln!("Stdout: {}", from_utf8(&bytes).unwrap()), TtyChunk::StdIn(_) => unreachable!(), } }
Output:
Stdout: 123 124 125 126 Stdout: 123 124 125 126 Stdout: 123 124 125 126 Stdout: 123 124 125 126 Stdout: 123 124 125 126 Stdout: 123 124 125 126 Stdout: 123 124 125 126 Stdout: 123 124 125 126 ..... forever
docker version
Background
Not sure if this a bug or I'm missing something here.
I'm copying a python file over and running it, but the Stream from
Container::exec
never seems to returnNone
. When I run throughdocker exec
it'll run once and exit.Output:
docker version
on the command line: 24.0.2