0

I am using Docker Remote API to run some commands, and I realised that the status is 200 even when the command I pass to it fails.

Example:

 curl -H "Content-Type: application/json" -X POST -d '{"AttachStdin":false,"AttachStdout":true,"AttachStderr":true,"Tty":true,"Cmd":["wrong"]}' http://localhost:2375/containers/console/exec

This returns an Id.

curl -v -H "Content-Type: application/json" -d '{"Detach":false,"Tty":false}' http://localhost:2375/exec/b64592543bc59e08de4d1d11c8a68415148a608b00aa62448284635f47eaa734/start

POST /exec/b64592543bc59e08de4d1d11c8a68415148a608b00aa62448284635f47eaa734/start HTTP/1.1 Host: myip:2375 User-Agent: curl/7.47.1 Accept: / Content-Type: application/json Content-Length: 28

HTTP/1.1 200 OK Content-Type: application/vnd.docker.raw-stream exec: "wrong": executable file not found in $PATH

The status code is 200, so is there another way to know whether the command ran on exec succeeded?

My current workaround is to pass something like this as the command:

bash -c 'command && echo SUCCEEDED_FLAG || echo FAILED_FLAG' and search for the flag later

PS: I used both postman and curl to test this.

Alberto Rivera
  • 3,652
  • 3
  • 19
  • 33

1 Answers1

2

You should inspect the exec result:

curl -v -H "Content-Type: application/json" http://localhost:2375/exec/b64592543bc59e08de4d1d11c8a68415148a608b00aa62448284635f47eaa734/json 

And check the value of ExitCode to get the exit code of the process you ran. See the exec inspect api docs for more details.

BMitch
  • 231,797
  • 42
  • 475
  • 450
  • Thank you. It looks like exactly what I need. I tried it before, but I used a POST request instead of GET, so I understandably got a 404. I will give it another try tomorrow. – Alberto Rivera Sep 21 '16 at 05:57