fussybeaver / bollard

Docker daemon API in Rust
Apache License 2.0
912 stars 134 forks source link

Stream doesn't close after exec log #374

Closed yooouuri closed 9 months ago

yooouuri commented 9 months ago

First, thanks for this crate. I have the following code:

#[tauri::command]
async fn create_exec_listener(container_name: String, command: String, app_handle: AppHandle) {
    // let handle = app_handle.clone();
    let docker = Docker::connect_with_socket("/Users/youri/.colima/docker.sock", 120, API_DEFAULT_VERSION).unwrap();

    let exec = docker
        .create_exec(
            container_name.as_str(),
            CreateExecOptions {
                attach_stdout: Some(true),
                attach_stderr: Some(true),
                attach_stdin: Some(true),
                tty: Some(true),
                cmd: Some(vec!["sh"]),
                ..Default::default()
            },
        )
        .await
        .unwrap()
        .id;

    if let StartExecResults::Attached {
        mut output,
        mut input,
    } = docker.start_exec(&exec, None).await.unwrap()
    {
        input.write(command.as_bytes()).await.ok();

        while let Some(Ok(output)) = output.next().await {
            println!("{}", output);
        }

        println!("done");
    }
}

How can I break out of the while loop? I need to send the user an event when the command is done.