dotnet / Docker.DotNet

:whale: .NET (C#) Client Library for Docker API
https://www.nuget.org/packages/Docker.DotNet/
MIT License
2.23k stars 381 forks source link

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

Open MJB222398 opened 11 months ago

MJB222398 commented 11 months ago

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: