code: public function cleanContainers($jobs = array())
      {
          $images     = array();
          $containers = array();
  
          foreach ($jobs as $job) {
              if (isset($job->getParameters()['image'])) {
                  $images[] = $job->getParameters()['image'];
              } else {
                  $images[] = sprintf('%s:%s', $job->getRepository(), $job->getTag());
              }
          }
  
          foreach ($this->docker->getContainerManager()->findAll(['all' => 1]) as $container) {
              $imageName = $container->getImage();
  
              foreach ($images as $image) {
                  if ($image == $imageName) {
                      $containers[] = $container;
                  }
  
                  if (preg_match('#^'.$imageName.'#', $image->getId())) {
                      $containers[] = $container;
                  }
              }
          }
  
          foreach ($containers as $container) {
              $this->docker->getContainerManager()->remove($container->getId(), [
                  'v' => true,
                  'force' => true
              ]);
          }
      }
docs: Clean images for given builds
  
  @param \Joli\JoliCi\Job[] $jobs A list of jobs to remove images from