Docker Community Forums

Share and learn in the Docker community.

Using docker exec via the API

(Sean Boran) #1


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” -d ‘{ “AttachStdin”:false,“AttachStdout”:true,“AttachStderr”:true, “Tty”:false, “Cmd”:["sh -c ls /var/www/html "] }’

curl -X POST -H “Content-Type: application/json”"“738a671bac1a6ae95b21877b19c6553c7b534834d85b19c3b18e01dbe462f935"”/start -d ‘{ “Detach”:false,“Tty”:false}’

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

Any suggestions?

(Sean Boran) #2

To answer myself, a working example

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


curl -X POST -H "Content-Type: application/json" -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" -d '{ "AttachStdin":false,"AttachStdout":true,"AttachStderr":true, "Tty":false, "Cmd":["/bin/bash", "-c", "ls /var/www/html"]