Skip to content

Container without ExposedPorts Warning #206

Closed

Description

@krzaczek

www: PHP Warning: [xxxxx.com] Invalid argument supplied for foreach() in .../vendor/docker-php/docker-php/generated/Normalizer/ContainerConfigNormalizer.php on line 198

This happens when the conataner has no exposed ports.

if (property_exists($data, 'ExposedPorts')) {
            $values_7 = new \ArrayObject([], \ArrayObject::ARRAY_AS_PROPS);
            foreach ($data->{'ExposedPorts'} as $key_1 => $value_13) {
                $values_7[$key_1] = $value_13;
            }
            $object->setExposedPorts($values_7);
        }

This should be checked like with Mounts

if (property_exists($data, 'Mounts')) {
            $value_11 = $data->{'Mounts'};
            if (is_array($data->{'Mounts'})) {
                $values_6 = [];
                foreach ($data->{'Mounts'} as $value_12) {
                    $values_6[] = $this->serializer->deserialize($value_12, 'Docker\\API\\Model\\Mount', 'raw', $context);
                }
                $value_11 = $values_6;
            }
            if (is_null($data->{'Mounts'})) {
                $value_11 = $data->{'Mounts'};
            }
            $object->setMounts($value_11);
        }

The property ExposedPorts exists but is NULL and foreach throws a Warning

This happens when I try to access container logs.

$response = $containerManager->find($data['container_id']);
...
$logs = $containerManager->logs($data['container_id'], ['stdout' => 1, 'stderr' => 1, 'tail' => 'all'], 'response');
$log = (string)$logs->getBody();

Activity

  1. krzaczek commented on Jun 14, 2016

    @krzaczek
    ContributorAuthor

    Example response from docker API shows that ExposedPorts can be null

    HTTP/1.1 200 OK
    Content-Type: application/json
    
    {
        "AppArmorProfile": "",
        "Args": [
            "-c",
            "exit 9"
        ],
        "Config": {
            "AttachStderr": true,
            "AttachStdin": false,
            "AttachStdout": true,
            "Cmd": [
                "/bin/sh",
                "-c",
                "exit 9"
            ],
            "Domainname": "",
            "Entrypoint": null,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "ExposedPorts": null,
            "Hostname": "ba033ac44011",
            "Image": "ubuntu",
            "Labels": {
                "com.example.vendor": "Acme",
                "com.example.license": "GPL",
                "com.example.version": "1.0"
            },
            "MacAddress": "",
            "NetworkDisabled": false,
            "OnBuild": null,
            "OpenStdin": false,
            "StdinOnce": false,
            "Tty": false,
            "User": "",
            "Volumes": {
                "/volumes/data": {}
            },
            "WorkingDir": "",
            "StopSignal": "SIGTERM"
        },
        "Created": "2015-01-06T15:47:31.485331387Z",
        "Driver": "devicemapper",
        "ExecDriver": "native-0.2",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "BlkioWeight": 0,
            "BlkioWeightDevice": [{}],
            "BlkioDeviceReadBps": [{}],
            "BlkioDeviceWriteBps": [{}],
            "BlkioDeviceReadIOps": [{}],
            "BlkioDeviceWriteIOps": [{}],
            "CapAdd": null,
            "CapDrop": null,
            "ContainerIDFile": "",
            "CpusetCpus": "",
            "CpusetMems": "",
            "CpuShares": 0,
            "CpuPeriod": 100000,
            "Devices": [],
            "Dns": null,
            "DnsOptions": null,
            "DnsSearch": null,
            "ExtraHosts": null,
            "IpcMode": "",
            "Links": null,
            "LxcConf": [],
            "Memory": 0,
            "MemorySwap": 0,
            "MemoryReservation": 0,
            "KernelMemory": 0,
            "OomKillDisable": false,
            "OomScoreAdj": 500,
            "NetworkMode": "bridge",
            "PortBindings": {},
            "Privileged": false,
            "ReadonlyRootfs": false,
            "PublishAllPorts": false,
            "RestartPolicy": {
                "MaximumRetryCount": 2,
                "Name": "on-failure"
            },
            "LogConfig": {
                "Config": null,
                "Type": "json-file"
            },
            "SecurityOpt": null,
            "VolumesFrom": null,
            "Ulimits": [{}],
            "VolumeDriver": "",
            "ShmSize": 67108864
        },
        "HostnamePath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/hostname",
        "HostsPath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/hosts",
        "LogPath": "/var/lib/docker/containers/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b/1eb5fabf5a03807136561b3c00adcd2992b535d624d5e18b6cdc6a6844d9767b-json.log",
        "Id": "ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39",
        "Image": "04c5d3b7b0656168630d3ba35d8889bd0e9caafcaeb3004d2bfbc47e7c5d35d2",
        "MountLabel": "",
        "Name": "/boring_euclid",
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": null,
            "SandboxKey": "",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "bridge": {
                    "NetworkID": "7ea29fc1412292a2d7bba362f9253545fecdfa8ce9a6e37dd10ba8bee7129812",
                    "EndpointID": "7587b82f0dada3656fda26588aee72630c6fab1536d36e394b2bfbcf898c971d",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:12:00:02"
                }
            }
        },
        "Path": "/bin/sh",
        "ProcessLabel": "",
        "ResolvConfPath": "/var/lib/docker/containers/ba033ac4401106a3b513bc9d639eee123ad78ca3616b921167cd74b20e25ed39/resolv.conf",
        "RestartCount": 1,
        "State": {
            "Error": "",
            "ExitCode": 9,
            "FinishedAt": "2015-01-06T15:47:32.080254511Z",
            "OOMKilled": false,
            "Dead": false,
            "Paused": false,
            "Pid": 0,
            "Restarting": false,
            "Running": true,
            "StartedAt": "2015-01-06T15:47:32.072697474Z",
            "Status": "running"
        },
        "Mounts": [
            {
                "Name": "fac362...80535",
                "Source": "/data",
                "Destination": "/data",
                "Driver": "local",
                "Mode": "ro,Z",
                "RW": false,
                "Propagation": ""
            }
        ]
    }
  2. joelwurtz commented on Aug 8, 2016

    @joelwurtz
    Member

    Thanks for the PR

  3. joelwurtz commented on Aug 8, 2016

    @joelwurtz
    Member

    Available in 1.23.2 version (and all 1.24+)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions