public function validateImageNames($containers, JobInterface $job)
 {
     // Verify that the appropriate container images exist
     $job->getOutput()->writeln("<comment>Validating container images exist</comment>");
     $docker = $job->getDocker();
     $manager = $docker->getImageManager();
     foreach ($containers as $key => $image_name) {
         $name = $image_name['image'];
         try {
             $image = $manager->find($name);
         } catch (ImageNotFoundException $e) {
             $job->errorOutput("Failed", "Required container image <options=bold>'{$name}'</options=bold> not found.");
             // TODO: Robust error handling.
             return FALSE;
         }
         $id = substr($image->getID(), 0, 8);
         $job->getOutput()->writeln("<comment>Found image <options=bold>{$name}</options=bold> with ID <options=bold>{$id}</options=bold></comment>");
     }
     return TRUE;
 }
 /**
  * {@inheritdoc}
  */
 public function run(JobInterface $job, $data)
 {
     // Data format: 'command [arguments]' or array('command [arguments]', 'command [arguments]')
     // $data May be a string if one version required, or array if multiple
     // Normalize data to the array format, if necessary
     $data = is_array($data) ? $data : [$data];
     $docker = $job->getDocker();
     $manager = $docker->getContainerManager();
     if (!empty($data)) {
         // Check that we have a container to execute on
         $configs = $job->getExecContainers();
         foreach ($configs as $type => $containers) {
             foreach ($containers as $container) {
                 $id = $container['id'];
                 $instance = $manager->find($id);
                 $short_id = substr($id, 0, 8);
                 $job->getOutput()->writeln("<info>Executing on container instance {$short_id}:</info>");
                 foreach ($data as $cmd) {
                     $job->getOutput()->writeln("<fg=magenta>{$cmd}</fg=magenta>");
                     $exec = explode(" ", $cmd);
                     $exec_id = $manager->exec($instance, $exec, TRUE, TRUE, TRUE, TRUE);
                     $job->getOutput()->writeln("<info>Command created as exec id " . substr($exec_id, 0, 8) . "</info>");
                     $result = $manager->execstart($exec_id, function ($output, $type) use($job) {
                         if ($type === 1) {
                             $job->getOutput()->writeln("<info>{$output}</info>");
                         } else {
                             $job->errorOutput('Error', $output);
                         }
                     });
                     //Response stream is never read you need to simulate a wait in order to get output
                     $result->getBody()->getContents();
                     $job->getOutput()->writeln((string) $result);
                 }
             }
         }
     }
 }