Beispiel #1
0
 /**
  * Execute docker command
  *
  * @param  string $containerName Container name
  * @param  string $envName       Environment variable
  *
  * @return string|bool|null
  */
 protected function getDockerEnv($containerName, $envName)
 {
     $ret = null;
     if (empty($containerName)) {
         $this->output->writeln('<p-error>No container specified</p-error>');
         return false;
     }
     if (empty($envName)) {
         $this->output->writeln('<p-error>No environment name specified</p-error>');
         return false;
     }
     // 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);
         // Get docker confguration (fetched directly from docker)
         $conf = \CliTools\Utility\DockerUtility::getDockerConfiguration($dockerContainerName);
         if (empty($conf)) {
             throw new \RuntimeException('Could not read docker configuration from container  "' . $dockerContainerName . '"');
         }
         if (!empty($conf->Config->Env[$envName])) {
             $ret = $conf->Config->Env[$envName];
         }
     }
     return $ret;
 }