interact with container bash with execStart · Issue #342 · docker-php/docker-php · GitHub
Skip to content
This repository was archived by the owner on Oct 26, 2019. It is now read-only.
This repository was archived by the owner on Oct 26, 2019. It is now read-only.

interact with container bash with execStart  #342

Description

@mohammadreza-soft74

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions