Inter docker通信(mqtt和python)

时间:2017-01-09 07:43:15

标签: docker containers ibm-cloud mqtt

我在IBM Bluemix中有两个docker容器。一个是MQTT和其他php-python。

PHP应用程序执行一个python脚本,该脚本应该连接到MQTT docker容器并订阅一个主题。

然而,php-python docker无法连接。它也无法ping到MQTT docker容器。

MQTT容器工作正常,因为我可以从本地计算机连接到它。

我尝试使用以下命令链接两个容器:

cf ic run -p 443 -p 80 --name connector --link moscacontainer:source 
registry.ng.bluemix.net/fortspace/php-mqtt

我已经为MQTT容器公开了端口1883和80。

我使用以下链接作为参考:

https://github.com/dceejay/nrdock/blob/master/README.md#linking-containers

有人可以指导吗?

编辑: cf ic的输出检查

[
    {
        "BluemixApp": null,
        "BluemixServices": null,
        "Config": {
            "AttachStderr": false,
            "AttachStdin": false,
            "AttachStdout": false,
            "Cmd": [],
            "Dns": "",
            "Env": [
                "logging_password=",
                "space_id=f874124c-cea6-460e-9bf2-b633eeeefcdf",
                "logstash_target=logmet.opvis.bluemix.net:9091",
                "metrics_target=logmet.opvis.bluemix.net:9095"
            ],
            "Hostname": "instance-0018c601",
            "Image": "registry.ng.bluemix.net/fortspace/php-mqtt:latest",
            "ImageArchitecture": "amd64",
            "Labels": {},
            "Memory": 256,
            "MemorySwap": "",
            "OpenStdin": true,
            "PortSpecs": "",
            "StdinOnce": false,
            "Tty": true,
            "User": "",
            "VCPU": 1,
            "VolumesFrom": "",
            "WorkingDir": ""
        },
        "ContainerState": "Running",
        "Created": "2017-01-11T06:21:38.000000000Z",
        "Group": {},
        "HostConfig": {
            "Binds": [],
            "CapAdd": [],
            "CapDrop": [],
            "ContainerIDFile": "",
            "Links": [
                "moscacontainer:source"
            ],
            "LogConfig": {
                "Config": {},
                "Type": "json-file"
            },
            "LxcConf": [],
            "PortBindings": {
                "443/tcp": [
                    {
                        "HostPort": "443"
                    }
                ],
                "80/tcp": [
                    {
                        "HostPort": "80"
                    }
                ]
            },
            "Privileged": false,
            "PublishAllPorts": false
        },
        "HostId": "46f8e5e8739f205e67ec852485095e953f079ff5c8f95b9e7c16f331",
        "Human_id": "connector",
        "Id": "4920a824-66bf-49bd-be71-549d0adeeffc",
        "Image": "sha256:080893a1e47927b2fdf3f24a8b0b803fab035c236551e32df9527654c8af698c",
        "Mounts": [],
        "Name": "connector",
        "NetworkSettings": {
            "Bridge": "",
            "Gateway": "",
            "IPAddress": "172.29.0.53",
            "IPPrefixLen": 0,
            "MacAddress": "fa:16:3e:3a:2e:04",
            "Networks": {
                "default": {
                    "Aliases": null,
                    "EndpointID": "4920a824-66bf-49bd-be71-549d0adeeffc",
                    "Gateway": "172.29.0.1",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "IPAMConfig": null,
                    "IPAddress": "172.29.0.53",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "Links": null,
                    "MacAddress": "fa:16:3e:3a:2e:04",
                    "NetworkID": "bd84d27c-8909-4dcc-a9cf-7dca5453f55c"
                }
            },
            "PortMapping": null,
            "Ports": {
                "443/tcp": [
                    {
                        "HostIp": "169.46.22.55",
                        "HostPort": "443"
                    }
                ],
                "80/tcp": [
                    {
                        "HostIp": "169.46.22.55",
                        "HostPort": "80"
                    }
                ]
            },
            "PublicIpAddress": "169.46.22.55"
        },
        "Path": "date",
        "ResolvConfPath": "/etc/resolv.conf",
        "State": {
            "Error": "",
            "ExitCode": 0,
            "FinishedAt": "0001-01-01T00:00:00Z",
            "Ghost": "",
            "Pid": 1,
            "Running": true,
            "StartedAt": "2017-01-11T06:22:54.000000000Z",
            "Status": "Running"
        },
        "Volumes": {},
        "VolumesRW": {}
    }
]

1 个答案:

答案 0 :(得分:0)

您可以查看此页面中的信息: https://console.ng.bluemix.net/docs/containers/container_linking.html

我担心--link是不正确的,您可能需要确保别名和名称是正确的。

此命令输出应该可以帮助您: cf ic inspect recipient_container_name