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

/bin/bash: sudo test -f /repositories/gubbins/file.txt && echo true: No such file or directory #655

Open
MJB222398 opened this issue Oct 2, 2023 · 0 comments

Comments

@MJB222398
Copy link

MJB222398 commented Oct 2, 2023

What version of Docker.DotNet?:

3.125.15

Steps to reproduce the issue:

I am trying to check if a file exists on a container. Doing this using a docker exec. I can run the command:

docker exec chrome-node /bin/bash -c "sudo test -f "/repositories/gubbins/file.txt" && echo "true""

In a bash shell and it will do as I desire.

However when I try to execute this using Docker.DotNet as below then it fails:

using (var tty = await _dockerClient.Exec.StartAndAttachContainerExecAsync(
    (await _dockerClient.Exec.ExecCreateContainerAsync(
        containerName,
        new ContainerExecCreateParameters
        {
            AttachStdin = true,
            AttachStderr = true,
            AttachStdout = true,
            Tty = true,
            Detach = false,
            Privileged = true,
            Cmd = new List<string>
            {
                "/bin/bash",
                "-c",
                "\"sudo test -f \"/repositories/gubbins/file.txt\" && echo \"true\"\"",
            }
        })).ID,
    true))
{
    var (stdOut, stdError) = await tty.ReadOutputToEndAsync(CancellationToken.None);
}

What actually happened?:

Standard Out is: /bin/bash: sudo test -f /repositories/gubbins/file.txt && echo true: No such file or directory

I have tried many permutations of quotes, double quotes, splitting command up etc but cannot get it to work. The issue appears to be that I am using '&&'. What is the correct way to do this?

What did you expect to happen?:

Expecting to be able to execute the command successfully

Additional information:

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

1 participant