# Using docker exec via the API

**URL:** <https://forums.docker.com/t/using-docker-exec-via-the-api/649>\
**Category:** Open Source Registry API\
**Created:** [January 19, 2015, 6:41am UTC](https://forums.docker.com/t/using-docker-exec-via-the-api/649 "2015-01-19T06:41:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![boran](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/boran/32/213_2.png) [@boran](https://forums.docker.com/u/boran)\
**Post date:** [January 19, 2015, 6:41am UTC](https://forums.docker.com/t/using-docker-exec-via-the-api/649/1 "2015-01-19T06:41:03Z")

</div>

Hi,

how can one do the equivalent of this via the API?  
docker exec mycontainer sh -c ‘/bin/ls /var/www/html’

Reading remote\_api\_v1.16/#exec-create it seems to be a two step process, tried this:

curl -X POST -H “Content-Type: application/json” [http://127.0.0.1:2375/containers/mycontainer/exec](http://127.0.0.1:2375/containers/mycontainer/exec) -d ‘{ “AttachStdin”:false,“AttachStdout”:true,“AttachStderr”:true, “Tty”:false, “Cmd”:["sh -c ls /var/www/html "] }’

curl -X POST -H “Content-Type: application/json” [http://127.0.0.1:2375/exec/](http://127.0.0.1:2375/exec/)"“738a671bac1a6ae95b21877b19c6553c7b534834d85b19c3b18e01dbe462f935"”/start -d ‘{ “Detach”:false,“Tty”:false}’

Gives:  
2015/01/19 06:39:26 docker-exec: failed to exec: exec: "sh -c ls /var/www/html ": stat sh -c ls /var/www/html : no such file or directory

Also tried stuff like  
/bin/ls

Any suggestions?

---

<div class="post-metadata">

**Author:** ![boran](https://sea3.discourse-cdn.com/docker/user_avatar/forums.docker.com/boran/32/213_2.png) [@boran](https://forums.docker.com/u/boran)\
**Post date:** [January 26, 2015, 2:35pm UTC](https://forums.docker.com/t/using-docker-exec-via-the-api/649/2 "2015-01-26T14:35:33Z")

</div>

To answer myself, a working example

```
curl -X POST -H "Content-Type: application/json" http://127.0.0.1:2375/containers/vanilla2/exec -d '{ "AttachStdin":false,"AttachStdout":true,"AttachStderr":true, "Tty":false, "Cmd":["/bin/date"] }'

{"Id":"213f4f0abd592b302a6af43637f4422f6387b63a9759643b3e6024655099b298"}

curl -X POST -H "Content-Type: application/json" http://127.0.0.1:2375/exec/213f4f0abd592b302a6af43637f4422f6387b63a9759643b3e6024655099b298/start -d '{ "Detach":false,"Tty":false}'

```

Mon Jan 26 14:33:59 UTC 2015

* * *

Example with argument “/bin/ls /var/www”

```
curl -X POST -H "Content-Type: application/json" http://127.0.0.1:2375/containers/vanilla2/exec -d '{ "AttachStdin":false,"AttachStdout":true,"AttachStderr":true, "Tty":false, "Cmd":["/bin/bash", "-c", "ls /var/www/html"]
```
