Using the rancher container exec api

Hi,

I’m trying to get this to work via the rancher container exec api. It works fine from the command line

sudo docker exec -i 3e8756acf56815459b7a50e36f889b1126792caf1fa14c6b7103678cfaf5d009 sh -c 'echo hello 123 >/data.txt

However if I make this request via the Rancher REST API:

HTTP/1.1 POST /v2-beta/projects/1a5/containers/1i177/?action=execute
Host: 192.168.13.129:8080
Accept: application/json
Content-Type: application/json
Content-Length: 98

{
"attachStdin": true,
"attachStdout": true,
"command": [
"sh -c 'echo hello 456 >/data.txt"
],
"tty": true
}

It returns the following error.

rpc error: code = 2 desc = oci runtime error: exec failed: exec: "sh -c 'echo hello 456 >/data.txt": stat sh -c 'echo hello 456 >/data.txt: no such file or directory

My guess is that the command field follows Dockerfile’s CMD setup. So try with:

"command": [
"sh",
"-c",
"echo hello 456 >/data.txt"
]

Yes, the command needs to be properly split as an array.

Thanks for the feedback. This is sort of working, however there’s a delay between me making the request via the api and the “docker exec” command being run against the container. This seems to be around 60 seconds.

Does anybody know if Is this configurable?