This repository was archived by the owner on Oct 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 269
This repository was archived by the owner on Oct 26, 2019. It is now read-only.
interact with container bash with execStart #342
Copy link
Copy link
Open
Description
I want to interact with bash. I get output from container but I can't send anything to container. i want to write container stdin but i cant .
It is very vital this issue. please answer quickly.
I think I should do something with Tty.
my snippet of code is below:
$remoteSocket ='192.168.85.34:2375';
$ssl = false;
// Connect to Docker
$client = DockerClientFactory::create([
'remote_socket' => $remoteSocket,
'ssl' => $ssl
]);
$docker = Docker::create($client);
$config = new ContainersCreatePostBody();
$config->setTty(true);
$config->setOpenStdin(true);
$config->setAttachStderr(true);
$config->setAttachStdout(true);
$config->setAttachStdin(true);
$config->setStdinOnce(false);
$config->setImage("test:2");
$creation = $docker->containerCreate($config);
$docker->containerStart($creation->getId());
$execConfig = new ContainersIdExecPostBody();
$execConfig->setTty(true);
$execConfig->setAttachStdout(true);
$execConfig->setAttachStderr(true);
$execConfig->setAttachStdin(true);
$execConfig->setCmd(['/bin/bash']);
$execid = $docker->containerExec($creation->getId(),$execConfig)->getId();
$execStartConfig = new ExecIdStartPostBody();
$execStartConfig->setDetach(false);
// Execute the command
$stream = $docker->execStart($execid,$execStartConfig);
$stream->onStdout(function ($stdout) {
echo $stdout;
});
$stream->onStderr(function ($stderr) {
print_r("err: ".$stderr."\n");
});
$stream->wait();
Thanks in advance.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels