Docker exec via rancher API

804 views Asked by At

I'm hoping that its possible to do this something like this via Rancher's REST API. Does anybody know if its possible?

cat data.txt | docker exec -i my_container sh -c 'cat >/data.txt'

Seems I can interact with docker exec using this:

curl -X "POST" "http://123.123.123.123:8080/v2-beta/containers/1i177?action=execute" \
     -H "Cookie: PL=rancher" \
     -H "Content-Type: application/json" \
     -u user:password \
     -d $'{
    "attachStdin": true,
   "attachStdout": true,
    "command": [
        "ls"
], 
"tty": true
}'

Which returns this:

url":"ws:\/\/123.123.123.123:8080\/v1\/exec\/"

So I assume I need to connect to this using a WebSocket?

1

There are 1 answers

2
Vincent Fiduccia On

Yes, with the token that was also included in that response either as a header (Authorization: Bearer <token>) or query param (?token=<token>).

You also probably want tty: false, since it is unlikely you are a TTY :-)