Skip to content

Can't execute command with bash shell #637

Open

Description

I am trying to automate running commands with docker exec. I have an example of a command that works from the command line, but can't get working in Docker.DotNet. With my container already running I opened a command line and ran: docker exec -it containerId bash -c "apt-get update". This command is successful and I can see the output from the command in the terminal window.

Then, I tried doing the same as:

ContainerExecCreateParameters execParams = new()
{
    AttachStderr = true,
    AttachStdout = true,
    Cmd = new[] { "//bin//bash", "apt-get update" }
};
    
var exec = await this.dockerClient.Exec.ExecCreateContainerAsync(containerId, execParams);
var stream = await this.dockerClient.Exec.StartAndAttachContainerExecAsync(exec.ID, false);
var output = await stream.ReadOutputToEndAsync(new CancellationToken());

Instead of getting the exepected output of apt-get update, I get the error message: (OCI runtime exec failed: exec failed: unable to start container process: exec: "apt-get update": executable file not found in $PATH: unknown , ).

I believe this error may be due to trying to execute the command not in the bash shell, but haven't found any examples or docs that demonstrate how to properly execute a command in the bash shell using Docker.DotNet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions