dotnet / dotnet/Docker.DotNet

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

Open
#655 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
2.4k
Forks
416
PR merge metrics
No merged PRs in 30d

Description

**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
{
"/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:**

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.