Hi,
A file can be uploaded to a container using the docker command line as follows
echo bar > /tmp/foo.txt
cat /tmp/foo.txt | docker exec -i vanilla2 sh -c 'cat >/tmp/dest.foo.txt’
docker exec -i vanilla2 sh -c ‘cat /tmp/dest.foo.txt’
Now, how to do this via the API?
There are two steps, create the “exec” and start it
In php with a buzzle client, one can create an exec instance:
$body = [
‘AttachStdin’ => true,
‘AttachStdout’ => true,
‘AttachStderr’ => true,
‘Tty’ => false,
‘Cmd’ => ["/bin/bash", “-c”, “cat >/tmp/dest.foo.txt”]
];
$response = $client->post([’/containers/{id}/exec’, [‘id’ => ‘vanilla2’]], [
‘body’ => Json::encode($body),
‘headers’ => [‘content-type’ => ‘application/json’],
]);
$execid=$response->json()[‘Id’];
Next, then to start that exec, its is unclear to me how to pipe in the stdin (i.e. the contenats of /tmp/foo.txt obove)
$body = ['Detach' => false, 'Tty' => $tty ];
$response = $client->post(['/exec/{id}/start', ['id' => $execid]], [
'body' => Json::encode($body),
'headers' => ['content-type' => 'application/json'],
]);
Reference doc is here: http://docs.docker.com/reference/api/docker_remote_api_v1.16/#exec-start
It talks about a stream result (for stdout/err), but how does one stream in stdin?
Any suggestions?