Exit Code 125 from Docker when Trying to Run Container Programmatically

Kit picture Kit · Dec 5, 2018 · Viewed 11.5k times · Source

I am trying to get an integration test working. In the test initialization phase I attempt to spin up a Redis server from a docker image.

var p = new Process { StartInfo = new ProcessStartInfo("docker", "run --name redistest –p 6379:6379 redis")};
p.Start();

When I do that the process exits with exit code 125. If I comment out those lines, hit a breakpoint in the test before the test code executes and instead run from the command line

docker run --name redistest -p 6379:6379 redis

the test runs as expected when continuing from the breakpoint. The 125 exist code just means docker run failed, so there's not much more information to go on.

Prior to either the command line invocation or the C# invocation, I made sure there was no container named redistest with

docker stop redistest
docker rm redistest

Yet the difference in behavior remains. All of these attempts to run docker programmatically fail:

  • adding -d
  • running as a normal user
  • running with elevated privileges
  • running from within a test
  • running from a .NET Framework console app

Why does programmatic process creation of the docker run command cause docker to exit with a 125?

It works programmatically just fine for some images but not others.

Answer

TheECanyon picture TheECanyon · Jan 16, 2019

Even though this is a month old I recently encountered this issue too. After removing --name from the run command it worked flawlessly. I could not figure out why it was behaving that way, but I am posting this here for people to see where it might not be necessary to specify a name.