Using docker exec via the API

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 -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/"“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?

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"]