Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't execute command with bash shell #637

Open
dsaffie opened this issue May 17, 2023 · 3 comments
Open

Can't execute command with bash shell #637

dsaffie opened this issue May 17, 2023 · 3 comments

Comments

@dsaffie
Copy link

dsaffie commented May 17, 2023

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.

@HofmeisterAn
Copy link
Contributor

HofmeisterAn commented May 17, 2023

Your are using two different commands (syntax) try:

Cmd = new[] { "/bin/bash", "-c", "apt-get update" }

@harry-123
Copy link

I have the same issue. I need to run the multiple commands from the bash, but
Cmd = new[] { "/bin/bash", "-c", "apt-get update" }

doesn't seems to be working.

@hakimdotdev
Copy link

hakimdotdev commented May 6, 2024

I have the same issue. I need to run the multiple commands from the bash, but Cmd = new[] { "/bin/bash", "-c", "apt-get update" }

doesn't seems to be working.

What is the response you get? What are the commands you're trying to run?

Cmd = new[] { "/bin/bash", "-c", "apt-get update" }

Works for me. The only point it fails is from a certain complexity or number of piped commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants