# Using the rancher container exec api

**URL:** <https://forums.suse.com/t/using-the-rancher-container-exec-api/5038>\
**Category:** Rancher 1.x\
**Created:** [December 29, 2016, 12:27pm UTC](https://forums.suse.com/t/using-the-rancher-container-exec-api/5038 "2016-12-29T12:27:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![carlskii](https://avatars.discourse-cdn.com/v4/letter/c/6de8d8/32.png) [@carlskii](https://forums.suse.com/u/carlskii)\
**Post date:** [December 29, 2016, 12:27pm UTC](https://forums.suse.com/t/using-the-rancher-container-exec-api/5038/1 "2016-12-29T12:27:38Z")

</div>

Hi,

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

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

```

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

```auto
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.

```auto
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

```

---

<div class="post-metadata">

**Author:** ![localhost](https://avatars.discourse-cdn.com/v4/letter/l/53a042/32.png) [@localhost](https://forums.suse.com/u/localhost)\
**Post date:** [December 29, 2016, 6:08pm UTC](https://forums.suse.com/t/using-the-rancher-container-exec-api/5038/2 "2016-12-29T18:08:45Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![vincent](https://sea2.discourse-cdn.com/flex022/user_avatar/forums.suse.com/vincent/32/7156_2.png) [@vincent](https://forums.suse.com/u/vincent)\
**Post date:** [December 30, 2016, 2:20am UTC](https://forums.suse.com/t/using-the-rancher-container-exec-api/5038/3 "2016-12-30T02:20:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![carlskii](https://avatars.discourse-cdn.com/v4/letter/c/6de8d8/32.png) [@carlskii](https://forums.suse.com/u/carlskii)\
**Post date:** [December 30, 2016, 3:20pm UTC](https://forums.suse.com/t/using-the-rancher-container-exec-api/5038/4 "2016-12-30T15:20:24Z")

</div>

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?
