Beispiel #1
0
 /**
  * Execute docker command
  *
  * @param  string                  $containerName Container name
  * @param  CommandBuilderInterface $comamnd       Command
  *
  * @return int|null|void
  */
 protected function executeDockerExec($containerName, CommandBuilderInterface $command)
 {
     if (empty($containerName)) {
         $this->output->writeln('<p-error>No container specified</p-error>');
         return 1;
     }
     if (!$command->isExecuteable()) {
         $this->output->writeln('<p-error>No command specified or not executeable</p-error>');
         return 1;
     }
     // Search updir for docker-compose.yml
     $path = $this->getDockerPath();
     if (!empty($path)) {
         // Genrate full docker container name
         $dockerContainerName = \CliTools\Utility\DockerUtility::getDockerInstanceName($containerName, 1, $path);
         // Switch to directory of docker-compose.yml
         PhpUtility::chdir($path);
         $this->output->writeln('<info>Executing "' . $command->getCommand() . '" in docker container "' . $dockerContainerName . '" ...</info>');
         $dockerCommand = new CommandBuilder('docker', 'exec -ti %s', array($dockerContainerName));
         $dockerCommand->append($command, false);
         $dockerCommand->executeInteractive();
     } else {
         $this->output->writeln('<p-error>No docker-compose.yml found in tree</p-error>');
         return 1;
     }
     return 0;
 }