bollard icon indicating copy to clipboard operation
bollard copied to clipboard

error when invalid command in `start_exec`?

Open jgsch opened this issue 2 years ago • 1 comments

Following examples/exec.rs with a wrong command unknown_command:

let docker = Docker::connect_with_socket_defaults()?;

let container_config = Config {
    image: Some(IMAGE),
    tty: Some(true),
    ..Default::default()
};

let container_id = docker
    .create_container::<&str, &str>(None, container_config)
    .await?
    .id;

docker
    .start_container::<String>(&container_id, None)
    .await?;

let cmd = vec!["unknown_command"];

let exec_id = docker
    .create_exec(
        &container_id,
        CreateExecOptions {
            attach_stdout: Some(true),
            attach_stderr: Some(true),
            cmd: ,
            ..Default::default()
        },
    )
    .await?
    .id;

let results = docker.start_exec(&exec_id, None).await?;

if let StartExecResults::Attached { mut output, .. } = results {
    while let Some(msg) = output.next().await {
        println!("output > {:?}", msg);
    }
}

The output is :

output > Ok(StdOut { message: b"OCI runtime exec failed: exec failed: container_linux.go:380: starting container process caused: exec: \"unknown_command\": executable file not found in $PATH: unknown\r\n" })

Shouldn't we have an Err or a StdErr somewhere? Or am I missing something?

(using bollard = "0.13")

jgsch avatar Aug 31 '22 08:08 jgsch

The raw Docker API doesn't expose the exit code of a container through the start_exec command, you would need to call wait_container after the execution to check what the status code was.

fussybeaver avatar Aug 31 '22 14:08 fussybeaver