Docker Community Forums

Share and learn in the Docker community.

How to stdin in docker execstart in docker-php api


#1
 $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(false);
$config->setAttachStdout(false);
$config->setAttachStdin(false);
$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);
//var_dump($stream);die();
// To see the output stream of the 'exec' command
$stdoutText = "";
$stderrText = "";
$stream->onStdout(function ($stdout) use (&$stdoutText) {
echo $stdout;
});
$stream->onStderr(function ($stderr) use (&$stderrText) {
print_r("err: ".$stderr."\n");
});
$stream->wait();

pleaaaaaaaaaaase HELP MEEEEE .
its my code . in this example i want to interact with bash . i get output from container but i can’t sent anything to container. i think i should do something with Tty !!!
thanks in advance.


#2

anybody does not help me?