/**
  * @param Container $container
  *
  * @return bool
  */
 private function isExposed(Container $container)
 {
     try {
         $this->docker->getContainerManager()->inspect($container);
     } catch (APIException $e) {
         // Happen on "docker build"
         return false;
     }
     $inspection = $container->getRuntimeInformations();
     if (empty($inspection['NetworkSettings']['Ports']) || empty($inspection['State']['Running'])) {
         return false;
     }
     return $inspection['State']['Running'];
 }
 private function listen()
 {
     $this->docker->listenEvents(function (Event $event) {
         if (null === $event->getId()) {
             return;
         }
         try {
             $response = $this->docker->getContainerManager()->find($event->getId(), [], ContainerManager::FETCH_RESPONSE);
             $container = json_decode(\GuzzleHttp\Psr7\copy_to_string($response->getBody()), true);
         } catch (\Exception $e) {
             return;
         }
         if (null === $container) {
             return;
         }
         if ($this->isExposed($container)) {
             $this->activeContainers[$container['Id']] = $container;
         } else {
             unset($this->activeContainers[$container['Id']]);
         }
         $this->write();
     });
 }