Skip to content

Exec Stream never ends #330

@chillcaw

Description

@chillcaw

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 return None. When I run through docker exec it'll run once and exit.

# 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
  • Crate version: master
  • OS: Window 10
  • Output of running docker version on the command line: 24.0.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions