Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Testcontainers ExecAsync fails to run /bin/ls

I’m trying to exec something on an Oracle container created by Testcontainers. If I run

docker exec [pid] /bin/ls -ltr

Then the command works, but if I use the code below, it throws an exception

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

        _container = new OracleBuilder()
            .Build();
        var result = await _container.ExecAsync(new[] { "/bin/ls -ltr" });
        if (result.ExitCode != 0)
        {
            throw new InvalidOperationException(result.Stdout + result.Stderr);
        }

OCI runtime exec failed: exec failed: unable to start container process: exec: "/bin/ls -ltr": stat /bin/ls -ltr: no such file or directory: unknown

>Solution :

The issue you’re experiencing with Testcontainers and the ExecAsync method failing to run /bin/ls could be due to a small mistake in how you’re passing the command arguments. Instead of passing "/bin/ls -ltr" as a single argument , you need to separate the command and its arguments into separate elements of the array.

Here’s an updated version of your code that should work:

_container = new OracleBuilder()
    .Build();
var result = await _container.ExecAsync(new[] { "/bin/ls" , "-ltr" });
if (result.ExitCode != 0)
{
    throw new InvalidOperationException(result.Stdout + result.Stderr);
}

By splitting "/bin/ls -ltr" into "/bin/ls" and "-ltr" , you’re providing the correct structure expected by the ExecAsync method. This way, it should properly execute the ls command with the -ltr flag inside the container.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading