示例#1
0
 /**
  * @return string
  * @throws ContainerException
  */
 public function start()
 {
     try {
         $containerConfig = new \Docker\API\Model\ContainerConfig();
         $containerConfig->setImage($this->image);
         $hostConfig = new \Docker\API\Model\HostConfig();
         $mapPorts = new \ArrayObject();
         $exposedPorts = new \ArrayObject();
         foreach ($this->ports as $from => $to) {
             $exposedPorts[$from] = new \stdClass();
             $hostPortBinding = new \Docker\API\Model\PortBinding();
             list($host, $port) = explode(':', $to);
             $hostPortBinding->setHostIp($host);
             if (!empty($port)) {
                 $hostPortBinding->setHostPort($port);
             }
             $mapPorts[$from] = [$hostPortBinding];
         }
         $containerConfig->setExposedPorts($exposedPorts);
         $hostConfig->setPortBindings($mapPorts);
         $hostConfig->setLinks($this->links);
         $hostConfig->setBinds($this->volumes);
         $containerConfig->setHostConfig($hostConfig);
         $envs = [];
         foreach ($this->envs as $k => $v) {
             $envs[] = $k . "=" . $v;
         }
         $containerConfig->setEnv($envs);
         $containerCreateResult = $this->containerManager->create($containerConfig);
         $this->containerId = $containerCreateResult->getId();
         $this->containerManager->start($this->containerId);
         return $this->containerId;
     } catch (ClientErrorException $e) {
         throw new ContainerException($e->getResponse()->getBody()->getContents(), $e->getCode(), $e);
     } catch (ServerErrorException $e) {
         throw new ContainerException($e->getResponse()->getBody()->getContents(), $e->getCode(), $e);
     } catch (\Exception $e) {
         throw new ContainerException($e->getMessage(), $e->getCode(), $e);
     }
 }
 public function denormalize($data, $class, $format = null, array $context = [])
 {
     if (empty($data)) {
         return null;
     }
     if (isset($data->{'$ref'})) {
         return new Reference($data->{'$ref'}, $context['rootSchema'] ?: null);
     }
     $object = new \Docker\API\Model\HostConfig();
     if (!isset($context['rootSchema'])) {
         $context['rootSchema'] = $object;
     }
     if (isset($data->{'Binds'})) {
         $values_3 = [];
         foreach ($data->{'Binds'} as $value_4) {
             $values_3[] = $value_4;
         }
         $object->setBinds($values_3);
     }
     if (isset($data->{'Links'})) {
         $values_5 = [];
         foreach ($data->{'Links'} as $value_6) {
             $values_5[] = $value_6;
         }
         $object->setLinks($values_5);
     }
     if (isset($data->{'LxcConf'})) {
         $values_7 = new \ArrayObject([], \ArrayObject::ARRAY_AS_PROPS);
         foreach ($data->{'LxcConf'} as $key_9 => $value_8) {
             $values_7[$key_9] = $value_8;
         }
         $object->setLxcConf($values_7);
     }
     if (isset($data->{'Memory'})) {
         $object->setMemory($data->{'Memory'});
     }
     if (isset($data->{'MemorySwap'})) {
         $object->setMemorySwap($data->{'MemorySwap'});
     }
     if (isset($data->{'CpuShares'})) {
         $object->setCpuShares($data->{'CpuShares'});
     }
     if (isset($data->{'CpuPeriod'})) {
         $object->setCpuPeriod($data->{'CpuPeriod'});
     }
     if (isset($data->{'CpusetCpus'})) {
         $object->setCpusetCpus($data->{'CpusetCpus'});
     }
     if (isset($data->{'CpusetMems'})) {
         $object->setCpusetMems($data->{'CpusetMems'});
     }
     if (isset($data->{'BlkioWeight'})) {
         $object->setBlkioWeight($data->{'BlkioWeight'});
     }
     if (isset($data->{'MemorySwappiness'})) {
         $object->setMemorySwappiness($data->{'MemorySwappiness'});
     }
     if (isset($data->{'OomKillDisable'})) {
         $object->setOomKillDisable($data->{'OomKillDisable'});
     }
     if (isset($data->{'PortBindings'})) {
         $values_10 = new \ArrayObject([], \ArrayObject::ARRAY_AS_PROPS);
         foreach ($data->{'PortBindings'} as $key_12 => $value_11) {
             $values_10[$key_12] = $this->serializer->deserialize($value_11, 'Docker\\API\\Model\\PortBinding', 'raw', $context);
         }
         $object->setPortBindings($values_10);
     }
     if (isset($data->{'PublishAllPorts'})) {
         $object->setPublishAllPorts($data->{'PublishAllPorts'});
     }
     if (isset($data->{'Privileged'})) {
         $object->setPrivileged($data->{'Privileged'});
     }
     if (isset($data->{'ReadonlyRootfs'})) {
         $object->setReadonlyRootfs($data->{'ReadonlyRootfs'});
     }
     if (isset($data->{'Dns'})) {
         $values_13 = [];
         foreach ($data->{'Dns'} as $value_14) {
             $values_13[] = $value_14;
         }
         $object->setDns($values_13);
     }
     if (isset($data->{'DnsSearch'})) {
         $values_15 = [];
         foreach ($data->{'DnsSearch'} as $value_16) {
             $values_15[] = $value_16;
         }
         $object->setDnsSearch($values_15);
     }
     if (isset($data->{'ExtraHosts'})) {
         $values_17 = [];
         foreach ($data->{'ExtraHosts'} as $value_18) {
             $values_17[] = $value_18;
         }
         $object->setExtraHosts($values_17);
     }
     if (isset($data->{'VolumesFrom'})) {
         $values_19 = [];
         foreach ($data->{'VolumesFrom'} as $value_20) {
             $values_19[] = $value_20;
         }
         $object->setVolumesFrom($values_19);
     }
     if (isset($data->{'CapAdd'})) {
         $values_21 = [];
         foreach ($data->{'CapAdd'} as $value_22) {
             $values_21[] = $value_22;
         }
         $object->setCapAdd($values_21);
     }
     if (isset($data->{'CapDrop'})) {
         $values_23 = [];
         foreach ($data->{'CapDrop'} as $value_24) {
             $values_23[] = $value_24;
         }
         $object->setCapDrop($values_23);
     }
     if (isset($data->{'RestartPolicy'})) {
         $object->setRestartPolicy($this->serializer->deserialize($data->{'RestartPolicy'}, 'Docker\\API\\Model\\RestartPolicy', 'raw', $context));
     }
     if (isset($data->{'NetworkMode'})) {
         $object->setNetworkMode($data->{'NetworkMode'});
     }
     if (isset($data->{'Devices'})) {
         $values_25 = [];
         foreach ($data->{'Devices'} as $value_26) {
             $values_25[] = $this->serializer->deserialize($value_26, 'Docker\\API\\Model\\Device', 'raw', $context);
         }
         $object->setDevices($values_25);
     }
     if (isset($data->{'Ulimits'})) {
         $values_27 = [];
         foreach ($data->{'Ulimits'} as $value_28) {
             $values_27[] = $this->serializer->deserialize($value_28, 'Docker\\API\\Model\\Ulimit', 'raw', $context);
         }
         $object->setUlimits($values_27);
     }
     if (isset($data->{'SecurityOpt'})) {
         $values_29 = [];
         foreach ($data->{'SecurityOpt'} as $value_30) {
             $values_29[] = $value_30;
         }
         $object->setSecurityOpt($values_29);
     }
     if (isset($data->{'LogConfig'})) {
         $object->setLogConfig($this->serializer->deserialize($data->{'LogConfig'}, 'Docker\\API\\Model\\LogConfig', 'raw', $context));
     }
     if (isset($data->{'CgroupParent'})) {
         $object->setCgroupParent($data->{'CgroupParent'});
     }
     return $object;
 }
示例#3
0
 /**
  * Uses Docker to deploy the given project to a live server
  * @param  \GitDeployer\Objects\Project $project The project to deploy
  * @param  string                       $gitpath The path to the checked-out project
  * @param  array                        $config  The configuration options to pass to this deployer
  * @return mixed
  */
 public function deploy(\GitDeployer\Objects\Project $project, $gitpath, $config)
 {
     $useTunnel = false;
     // -> Connect to the docker daemon on a tcp or unix socket
     if (!isset($config['host']) || strlen($config['host']) < 1) {
         $config['host'] = getenv('DOCKER_HOST');
     }
     if (strlen($config['host']) < 1) {
         throw new \Exception('Neither the "host" parameter was specified in the .deployer file nor is the DOCKER_HOST environment variable set!');
     }
     if (stristr($config['host'], 'tcp://')) {
         // Setting the docker host to tcp:// may enable usage of the SSH tunnel functionality
         if (isset($config['ssh']) && is_array($config['ssh'])) {
             if (isset($config['ssh']['tunnel']) && $config['ssh']['tunnel'] == true) {
                 $useProc = false;
                 $useTunnel = true;
                 parent::showMessage('DOCKER', 'Connecting to Docker daemon via SSH...', $this->output);
                 // Check if the ssh binary is executable, else bail out
                 // since we can't open a tunnel without it
                 if (!$this->commandExists('ssh')) {
                     throw new \Exception('SSH client not found: Please make sure the "ssh" command is available, and in your $PATH!');
                 } else {
                     if (!isset($config['ssh']['host']) || strlen($config['ssh']['host']) < 1) {
                         throw new \Exception('Please specify at least a SSH host in your .deployerfile to connect to!');
                     }
                     if (!isset($config['ssh']['user']) || strlen($config['ssh']['user']) < 1) {
                         $config['ssh']['user'] = "******";
                     }
                     $config['ssh']['port'] = isset($config['ssh']['port']) && strlen($config['ssh']['port']) > 0 ? $config['ssh']['port'] : 22;
                     if (!isset($config['ssh']['privatekey']) || strlen($config['ssh']['privatekey']) < 1) {
                         throw new \Exception('Please correctly specify your SSH private key in the .deployerfile!');
                     }
                     // -> Open tunnel via SSH command
                     $randport = rand(60000, 65000);
                     $remotedesc = str_replace('tcp://', '', $config['host']);
                     $cmdstring = 'ssh -N -i ' . escapeshellarg($config['ssh']['privatekey']) . ' -L ' . $randport . ':' . $remotedesc . ' -p ' . $config['ssh']['port'] . ' ' . $config['ssh']['user'] . '@' . $config['ssh']['host'];
                     if (isset($config['ssh']['password']) && strlen($config['ssh']['password']) > 1) {
                         if (!extension_loaded('expect')) {
                             throw new \Exception('Expect extension not found: Please make sure the PHP expect extension is available in your PHP installation!');
                         }
                         $stream = fopen('expect://' . $cmdstring, 'r');
                         $cases = array(array('Enter passphrase', PASSWORD));
                         ini_set("expect.timeout", 30);
                         switch (expect_expectl($stream, $cases)) {
                             case PASSWORD:
                                 fwrite($stream, $config['ssh']['password'] . "\n");
                                 // Wait for tunnel port to be available
                                 while (true) {
                                     $socket = @fsockopen('127.0.0.1', $randport, $errno, $errstr, 5);
                                     if ($socket) {
                                         fclose($socket);
                                         break;
                                     }
                                 }
                                 break;
                             default:
                                 throw new \Exception('Unable to connect to the remote SSH host! Invalid string received: Expected passphrase prompt.');
                         }
                     } else {
                         $stream = proc_open('exec ' . $cmdstring, array(), $pipes);
                         $useProc = true;
                         // Wait for tunnel port to be available
                         while (true) {
                             $socket = @fsockopen('127.0.0.1', $randport, $errno, $errstr, 5);
                             if ($socket) {
                                 fclose($socket);
                                 break;
                             }
                         }
                     }
                 }
             }
         }
     }
     $client = new \Docker\DockerClient(array('remote_socket' => 'tcp://127.0.0.1:' . $randport, 'ssl' => isset($config['ssl']) && $config['ssl'] == true ? true : false));
     $docker = new \Docker\Docker($client);
     // -> Build the docker image if a Dockerfile is present
     if (!file_exists($gitpath . '/Dockerfile')) {
         throw new \Exception('No Dockerfile found - aborting build!');
     }
     parent::showMessage('DOCKER', 'Building image (no-cache)...', $this->output);
     parent::showMessage('DOCKER', 'Uploading context...', $this->output);
     $context = new \Docker\Context\Context($gitpath);
     $imageManager = $docker->getImageManager();
     $buildStream = $imageManager->build($context->toStream(), array('t' => 'git-deployer/' . $project->name()), \Docker\Manager\ContainerManager::FETCH_STREAM);
     $buildStream->onFrame(function (\Docker\API\Model\BuildInfo $buildInfo) {
         parent::showMessage('BUILD', $buildInfo->getStream(), $this->output);
     });
     $buildStream->wait();
     // -> Stop and remove the old container with the same name, sicne we're going
     // to replace the app here with the newly built container
     parent::showMessage('DOCKER', 'Getting running containers...', $this->output);
     $containersOnHost = $docker->getContainerManager()->findAll();
     if (count($containersOnHost) > 0) {
         // We check for a container with the same name as the one we are going to deploy
         foreach ($containersOnHost as $key => $container) {
             $containerFound = false;
             // Search by name
             foreach ($container->getNames() as $name) {
                 $cleanName = $this->cleanName($project->name());
                 preg_match('#\\/.*\\/(.*)#', $name, $matches);
                 if ($cleanName == $matches[1]) {
                     $containerFound = true;
                 }
             }
             // Search by image
             if ($container->getImage() == 'git-deployer/' . $project->name()) {
                 $containerFound = true;
             }
             if ($containerFound) {
                 parent::showMessage('DOCKER', 'Stopping old container ' . $container->getId() . '...', $this->output);
                 $docker->getContainerManager()->stop($container->getId());
                 $docker->getContainerManager()->remove($container->getId());
             }
         }
     }
     // -> Start the container up if we have built sucessfully
     parent::showMessage('DOCKER', 'Starting new container...', $this->output);
     $hostConfig = new \Docker\API\Model\HostConfig();
     $containerConfig = new \Docker\API\Model\ContainerConfig();
     $containerConfig->setNames(array('git-deployer/' . $this->cleanName($project->name())));
     $containerConfig->setImage('git-deployer/' . $project->name());
     // Add environment from the config file, if any
     $envArray = array();
     if (isset($config['environment'])) {
         foreach ($config['environment'] as $key => $value) {
             $envArray[] = $key . '=' . $value;
         }
     }
     $containerConfig->setEnv($envArray);
     // Add exposed ports from the config file, if any
     if (isset($config['ports']) && is_array($config['ports']) && count($config['ports']) > 0) {
         $exposedPorts = new \ArrayObject();
         $mapPorts = new \ArrayObject();
         foreach ($config['ports'] as $portdesc) {
             $portspec = $this->parsePortSpecification($portdesc);
             // Exposed port
             $exposedPort = $portspec['port'] . (strlen($portspec['protocol']) > 0 ? '/' . $portspec['protocol'] : '/tcp');
             $exposedPorts[$exposedPort] = new \stdClass();
             // Host port binding
             $hostPortBinding = new \Docker\API\Model\PortBinding();
             $mapPorts[$exposedPort] = array($hostPortBinding);
         }
         $containerConfig->setExposedPorts($exposedPorts);
         $hostConfig->setPortBindings($mapPorts);
     }
     // Add restart policy
     if (isset($config['restart']) && strlen($config['restart']) > 0) {
         $policy = $this->parseRestartPolicy($config['restart']);
         $restartPolicy = new \Docker\API\Model\RestartPolicy();
         $restartPolicy->setName($policy['Name']);
         if (isset($policy['MaximumRetryCount'])) {
             $restartPolicy->setMaximumRetryCount($policy['MaximumRetryCount']);
         }
         $hostConfig->setRestartPolicy($restartPolicy);
     }
     // Add binds
     if (isset($config['volumes']) && is_array($config['volumes']) && count($config['volumes']) > 0) {
         $binds = new \ArrayObject();
         foreach ($config['volumes'] as $volume) {
             $binds[] = $volume;
         }
         $hostConfig->setBinds($binds);
     }
     $containerConfig->setHostConfig($hostConfig);
     $containerCreateResult = $docker->getContainerManager()->create($containerConfig, array('name' => $this->cleanName($project->name())));
     if ($containerCreateResult->getId()) {
         $docker->getContainerManager()->start($containerCreateResult->getId());
     }
     // -> Clean up and close the SSH tunnel
     if ($useTunnel) {
         if ($useProc) {
             proc_terminate($stream, 9);
             proc_close($stream);
         } else {
             fclose($stream);
         }
     }
     return array(true, 'No trace');
 }
 public function denormalize($data, $class, $format = null, array $context = [])
 {
     if (empty($data)) {
         return null;
     }
     if (isset($data->{'$ref'})) {
         return new Reference($data->{'$ref'}, $context['rootSchema'] ?: null);
     }
     $object = new \Docker\API\Model\HostConfig();
     if (!isset($context['rootSchema'])) {
         $context['rootSchema'] = $object;
     }
     if (property_exists($data, 'Binds')) {
         $value = $data->{'Binds'};
         if (is_array($data->{'Binds'})) {
             $values = [];
             foreach ($data->{'Binds'} as $value_1) {
                 $values[] = $value_1;
             }
             $value = $values;
         }
         if (is_null($data->{'Binds'})) {
             $value = $data->{'Binds'};
         }
         $object->setBinds($value);
     }
     if (property_exists($data, 'Links')) {
         $value_2 = $data->{'Links'};
         if (is_array($data->{'Links'})) {
             $values_1 = [];
             foreach ($data->{'Links'} as $value_3) {
                 $values_1[] = $value_3;
             }
             $value_2 = $values_1;
         }
         if (is_null($data->{'Links'})) {
             $value_2 = $data->{'Links'};
         }
         $object->setLinks($value_2);
     }
     if (property_exists($data, 'LxcConf')) {
         $values_2 = new \ArrayObject([], \ArrayObject::ARRAY_AS_PROPS);
         foreach ($data->{'LxcConf'} as $key => $value_4) {
             $values_2[$key] = $value_4;
         }
         $object->setLxcConf($values_2);
     }
     if (property_exists($data, 'Memory')) {
         $object->setMemory($data->{'Memory'});
     }
     if (property_exists($data, 'MemorySwap')) {
         $object->setMemorySwap($data->{'MemorySwap'});
     }
     if (property_exists($data, 'CpuShares')) {
         $object->setCpuShares($data->{'CpuShares'});
     }
     if (property_exists($data, 'CpuPeriod')) {
         $object->setCpuPeriod($data->{'CpuPeriod'});
     }
     if (property_exists($data, 'CpusetCpus')) {
         $object->setCpusetCpus($data->{'CpusetCpus'});
     }
     if (property_exists($data, 'CpusetMems')) {
         $object->setCpusetMems($data->{'CpusetMems'});
     }
     if (property_exists($data, 'BlkioWeight')) {
         $object->setBlkioWeight($data->{'BlkioWeight'});
     }
     if (property_exists($data, 'BlkioWeightDevice')) {
         $value_5 = $data->{'BlkioWeightDevice'};
         if (is_array($data->{'BlkioWeightDevice'})) {
             $values_3 = [];
             foreach ($data->{'BlkioWeightDevice'} as $value_6) {
                 $values_3[] = $this->serializer->deserialize($value_6, 'Docker\\API\\Model\\DeviceWeight', 'raw', $context);
             }
             $value_5 = $values_3;
         }
         if (is_null($data->{'BlkioWeightDevice'})) {
             $value_5 = $data->{'BlkioWeightDevice'};
         }
         $object->setBlkioWeightDevice($value_5);
     }
     if (property_exists($data, 'BlkioDeviceReadBps')) {
         $value_7 = $data->{'BlkioDeviceReadBps'};
         if (is_array($data->{'BlkioDeviceReadBps'})) {
             $values_4 = [];
             foreach ($data->{'BlkioDeviceReadBps'} as $value_8) {
                 $values_4[] = $this->serializer->deserialize($value_8, 'Docker\\API\\Model\\DeviceRate', 'raw', $context);
             }
             $value_7 = $values_4;
         }
         if (is_null($data->{'BlkioDeviceReadBps'})) {
             $value_7 = $data->{'BlkioDeviceReadBps'};
         }
         $object->setBlkioDeviceReadBps($value_7);
     }
     if (property_exists($data, 'BlkioDeviceReadIOps')) {
         $value_9 = $data->{'BlkioDeviceReadIOps'};
         if (is_array($data->{'BlkioDeviceReadIOps'})) {
             $values_5 = [];
             foreach ($data->{'BlkioDeviceReadIOps'} as $value_10) {
                 $values_5[] = $this->serializer->deserialize($value_10, 'Docker\\API\\Model\\DeviceRate', 'raw', $context);
             }
             $value_9 = $values_5;
         }
         if (is_null($data->{'BlkioDeviceReadIOps'})) {
             $value_9 = $data->{'BlkioDeviceReadIOps'};
         }
         $object->setBlkioDeviceReadIOps($value_9);
     }
     if (property_exists($data, 'BlkioDeviceWriteBps')) {
         $value_11 = $data->{'BlkioDeviceWriteBps'};
         if (is_array($data->{'BlkioDeviceWriteBps'})) {
             $values_6 = [];
             foreach ($data->{'BlkioDeviceWriteBps'} as $value_12) {
                 $values_6[] = $this->serializer->deserialize($value_12, 'Docker\\API\\Model\\DeviceRate', 'raw', $context);
             }
             $value_11 = $values_6;
         }
         if (is_null($data->{'BlkioDeviceWriteBps'})) {
             $value_11 = $data->{'BlkioDeviceWriteBps'};
         }
         $object->setBlkioDeviceWriteBps($value_11);
     }
     if (property_exists($data, 'BlkioDeviceWriteIOps')) {
         $value_13 = $data->{'BlkioDeviceWriteIOps'};
         if (is_array($data->{'BlkioDeviceWriteIOps'})) {
             $values_7 = [];
             foreach ($data->{'BlkioDeviceWriteIOps'} as $value_14) {
                 $values_7[] = $this->serializer->deserialize($value_14, 'Docker\\API\\Model\\DeviceRate', 'raw', $context);
             }
             $value_13 = $values_7;
         }
         if (is_null($data->{'BlkioDeviceWriteIOps'})) {
             $value_13 = $data->{'BlkioDeviceWriteIOps'};
         }
         $object->setBlkioDeviceWriteIOps($value_13);
     }
     if (property_exists($data, 'MemorySwappiness')) {
         $object->setMemorySwappiness($data->{'MemorySwappiness'});
     }
     if (property_exists($data, 'OomKillDisable')) {
         $object->setOomKillDisable($data->{'OomKillDisable'});
     }
     if (property_exists($data, 'OomScoreAdj')) {
         $object->setOomScoreAdj($data->{'OomScoreAdj'});
     }
     if (property_exists($data, 'PidsLimit')) {
         $object->setPidsLimit($data->{'PidsLimit'});
     }
     if (property_exists($data, 'PortBindings')) {
         $value_15 = $data->{'PortBindings'};
         if (is_object($data->{'PortBindings'})) {
             $values_8 = new \ArrayObject([], \ArrayObject::ARRAY_AS_PROPS);
             foreach ($data->{'PortBindings'} as $key_1 => $value_16) {
                 $value_17 = $value_16;
                 if (is_array($value_16)) {
                     $values_9 = [];
                     foreach ($value_16 as $value_18) {
                         $values_9[] = $this->serializer->deserialize($value_18, 'Docker\\API\\Model\\PortBinding', 'raw', $context);
                     }
                     $value_17 = $values_9;
                 }
                 if (is_null($value_16)) {
                     $value_17 = $value_16;
                 }
                 $values_8[$key_1] = $value_17;
             }
             $value_15 = $values_8;
         }
         if (is_null($data->{'PortBindings'})) {
             $value_15 = $data->{'PortBindings'};
         }
         $object->setPortBindings($value_15);
     }
     if (property_exists($data, 'PublishAllPorts')) {
         $object->setPublishAllPorts($data->{'PublishAllPorts'});
     }
     if (property_exists($data, 'Privileged')) {
         $object->setPrivileged($data->{'Privileged'});
     }
     if (property_exists($data, 'ReadonlyRootfs')) {
         $object->setReadonlyRootfs($data->{'ReadonlyRootfs'});
     }
     if (property_exists($data, 'Dns')) {
         $value_19 = $data->{'Dns'};
         if (is_array($data->{'Dns'})) {
             $values_10 = [];
             foreach ($data->{'Dns'} as $value_20) {
                 $values_10[] = $value_20;
             }
             $value_19 = $values_10;
         }
         if (is_null($data->{'Dns'})) {
             $value_19 = $data->{'Dns'};
         }
         $object->setDns($value_19);
     }
     if (property_exists($data, 'DnsOptions')) {
         $value_21 = $data->{'DnsOptions'};
         if (is_array($data->{'DnsOptions'})) {
             $values_11 = [];
             foreach ($data->{'DnsOptions'} as $value_22) {
                 $values_11[] = $value_22;
             }
             $value_21 = $values_11;
         }
         if (is_null($data->{'DnsOptions'})) {
             $value_21 = $data->{'DnsOptions'};
         }
         $object->setDnsOptions($value_21);
     }
     if (property_exists($data, 'DnsSearch')) {
         $value_23 = $data->{'DnsSearch'};
         if (is_array($data->{'DnsSearch'})) {
             $values_12 = [];
             foreach ($data->{'DnsSearch'} as $value_24) {
                 $values_12[] = $value_24;
             }
             $value_23 = $values_12;
         }
         if (is_null($data->{'DnsSearch'})) {
             $value_23 = $data->{'DnsSearch'};
         }
         $object->setDnsSearch($value_23);
     }
     if (property_exists($data, 'ExtraHosts')) {
         $value_25 = $data->{'ExtraHosts'};
         if (is_array($data->{'ExtraHosts'})) {
             $values_13 = [];
             foreach ($data->{'ExtraHosts'} as $value_26) {
                 $values_13[] = $value_26;
             }
             $value_25 = $values_13;
         }
         if (is_null($data->{'ExtraHosts'})) {
             $value_25 = $data->{'ExtraHosts'};
         }
         $object->setExtraHosts($value_25);
     }
     if (property_exists($data, 'VolumesFrom')) {
         $value_27 = $data->{'VolumesFrom'};
         if (is_array($data->{'VolumesFrom'})) {
             $values_14 = [];
             foreach ($data->{'VolumesFrom'} as $value_28) {
                 $values_14[] = $value_28;
             }
             $value_27 = $values_14;
         }
         if (is_null($data->{'VolumesFrom'})) {
             $value_27 = $data->{'VolumesFrom'};
         }
         $object->setVolumesFrom($value_27);
     }
     if (property_exists($data, 'CapAdd')) {
         $value_29 = $data->{'CapAdd'};
         if (is_array($data->{'CapAdd'})) {
             $values_15 = [];
             foreach ($data->{'CapAdd'} as $value_30) {
                 $values_15[] = $value_30;
             }
             $value_29 = $values_15;
         }
         if (is_null($data->{'CapAdd'})) {
             $value_29 = $data->{'CapAdd'};
         }
         $object->setCapAdd($value_29);
     }
     if (property_exists($data, 'CapDrop')) {
         $value_31 = $data->{'CapDrop'};
         if (is_array($data->{'CapDrop'})) {
             $values_16 = [];
             foreach ($data->{'CapDrop'} as $value_32) {
                 $values_16[] = $value_32;
             }
             $value_31 = $values_16;
         }
         if (is_null($data->{'CapDrop'})) {
             $value_31 = $data->{'CapDrop'};
         }
         $object->setCapDrop($value_31);
     }
     if (property_exists($data, 'GroupAdd')) {
         $value_33 = $data->{'GroupAdd'};
         if (is_array($data->{'GroupAdd'})) {
             $values_17 = [];
             foreach ($data->{'GroupAdd'} as $value_34) {
                 $values_17[] = $value_34;
             }
             $value_33 = $values_17;
         }
         if (is_null($data->{'GroupAdd'})) {
             $value_33 = $data->{'GroupAdd'};
         }
         $object->setGroupAdd($value_33);
     }
     if (property_exists($data, 'RestartPolicy')) {
         $object->setRestartPolicy($this->serializer->deserialize($data->{'RestartPolicy'}, 'Docker\\API\\Model\\RestartPolicy', 'raw', $context));
     }
     if (property_exists($data, 'UsernsMode')) {
         $object->setUsernsMode($data->{'UsernsMode'});
     }
     if (property_exists($data, 'NetworkMode')) {
         $object->setNetworkMode($data->{'NetworkMode'});
     }
     if (property_exists($data, 'Devices')) {
         $value_35 = $data->{'Devices'};
         if (is_array($data->{'Devices'})) {
             $values_18 = [];
             foreach ($data->{'Devices'} as $value_36) {
                 $values_18[] = $this->serializer->deserialize($value_36, 'Docker\\API\\Model\\Device', 'raw', $context);
             }
             $value_35 = $values_18;
         }
         if (is_null($data->{'Devices'})) {
             $value_35 = $data->{'Devices'};
         }
         $object->setDevices($value_35);
     }
     if (property_exists($data, 'Ulimits')) {
         $value_37 = $data->{'Ulimits'};
         if (is_array($data->{'Ulimits'})) {
             $values_19 = [];
             foreach ($data->{'Ulimits'} as $value_38) {
                 $values_19[] = $this->serializer->deserialize($value_38, 'Docker\\API\\Model\\Ulimit', 'raw', $context);
             }
             $value_37 = $values_19;
         }
         if (is_null($data->{'Ulimits'})) {
             $value_37 = $data->{'Ulimits'};
         }
         $object->setUlimits($value_37);
     }
     if (property_exists($data, 'SecurityOpt')) {
         $value_39 = $data->{'SecurityOpt'};
         if (is_array($data->{'SecurityOpt'})) {
             $values_20 = [];
             foreach ($data->{'SecurityOpt'} as $value_40) {
                 $values_20[] = $value_40;
             }
             $value_39 = $values_20;
         }
         if (is_null($data->{'SecurityOpt'})) {
             $value_39 = $data->{'SecurityOpt'};
         }
         $object->setSecurityOpt($value_39);
     }
     if (property_exists($data, 'LogConfig')) {
         $object->setLogConfig($this->serializer->deserialize($data->{'LogConfig'}, 'Docker\\API\\Model\\LogConfig', 'raw', $context));
     }
     if (property_exists($data, 'CgroupParent')) {
         $object->setCgroupParent($data->{'CgroupParent'});
     }
     if (property_exists($data, 'VolumeDriver')) {
         $object->setVolumeDriver($data->{'VolumeDriver'});
     }
     if (property_exists($data, 'ShmSize')) {
         $object->setShmSize($data->{'ShmSize'});
     }
     return $object;
 }