Skip to content
This repository was archived by the owner on Oct 26, 2019. It is now read-only.

Update container-run.md - #320

Merged
joelwurtz merged 2 commits into
docker-php:masterfrom
dbjpanda:master
Feb 17, 2019
Merged

Update container-run.md#320
joelwurtz merged 2 commits into
docker-php:masterfrom
dbjpanda:master

Conversation

@dbjpanda

Copy link
Copy Markdown
Contributor

Added an example for executing command on running container.

dbjpanda added 2 commits June 18, 2018 02:42
Added an example for executing command on running container.
Comment thread docs/cookbook/container-run.md
@dbjpanda

Copy link
Copy Markdown
Contributor Author

@joelwurtz Can you merge it if it looks good for you.

@michaelradionov

Copy link
Copy Markdown

please merge it! so helpful!

@mohammadreza-soft74

Copy link
Copy Markdown

@dbjpanda how can i write to container STDIN on exec.
for example i want run python code that need input .
how can i give input?
thanks in advance

@dbjpanda

dbjpanda commented Dec 5, 2018

Copy link
Copy Markdown
Contributor Author

$execConfig->setCmd(['/run.py',$arguments]);
Did you try this ? Note run.py should be present there in your py container.

@mohammadreza-soft74

mohammadreza-soft74 commented Dec 5, 2018

Copy link
Copy Markdown

@dbjpanda yes i try it . but i want to interact with python app.

$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);

$stream->onStdout(function ($stdout)  {
    echo $stdout;

});
$stream->onStderr(function ($stderr) {
    print_r("err: ".$stderr."\n");
});

$stream->wait();

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

@mohammadreza-soft74

Copy link
Copy Markdown

anybody does not help me?
It is very vital this issue

@joelwurtz

Copy link
Copy Markdown
Member

Thanks @dbjpanda it should be correct yes.

@mohammadreza-soft74 I don't think this is possible with current endpoints, it needs to use the HTTP hijacking way of doing thing from docker (there is no Websocket endpoint). And this is not supported in this library ATM.

@joelwurtz
joelwurtz merged commit d3a7aaf into docker-php:master Feb 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants