Docker IP容器而不是HOST IP。 Web服务请求。 WAS7

时间:2017-09-12 09:41:22

标签: web-services docker ip containers

我在Docker容器中的WAS7上运行我的app webservices。 当我尝试从端点获取请求时 http://172.25.121.54(dockerHost):9080/ufservices/services/UFDocumentServiceEndpoint/我得到: http://172.18.0.1:9080/ufservices/services/UFDocumentServiceEndpoint/ 这是ip形式的Docker网桥:

$ docker network inspect siecDocker

[
    {
        "Name": "siecDocker",
        "Id": "49bd1ff621f799fd75eb5237b9384f7c525cb5e7d45015f5b076b5a04e677a83",
        "Created": "2017-09-11T16:17:19.1806053+02:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "172.18.0.0/16",
                    "Gateway": "172.18.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {},
        "Options": {},
        "Labels": {}
    }
]

我尝试使用--net = host或static ip运行容器,结果是一样的。

$ docker run -d --net=host --name mycontainer -p 1521:1521 -p 1522:1522 -p 9080:9080 -p 9043:9043 -p 9060:9060 myimageid
$ ip addr on DOCKER HOST


1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:1d:d8:b7:21:90 brd ff:ff:ff:ff:ff:ff
    inet 172.25.121.54/24 brd 172.25.121.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet 172.25.121.54/22 brd 172.25.123.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::21d:d8ff:feb7:2190/64 scope link
       valid_lft forever preferred_lft forever
3: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
    link/ether 02:42:c9:e0:bc:23 brd ff:ff:ff:ff:ff:ff
    inet 172.17.0.1/16 scope global docker0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:c9ff:fee0:bc23/64 scope link
       valid_lft forever preferred_lft forever
4: br-8dd2c7730da7: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN
    link/ether 02:42:97:86:d7:0c brd ff:ff:ff:ff:ff:ff
    inet 172.18.0.1/16 scope global br-8dd2c7730da7
       valid_lft forever preferred_lft forever
5: br-ce802d519cf0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN
    link/ether 02:42:7b:03:20:a4 brd ff:ff:ff:ff:ff:ff
    inet 172.18.0.1/16 scope global br-ce802d519cf0
       valid_lft forever preferred_lft forever
50: br-49bd1ff621f7: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
    link/ether 02:42:e0:9e:7a:ab brd ff:ff:ff:ff:ff:ff
    inet 172.18.0.1/16 scope global br-49bd1ff621f7
       valid_lft forever preferred_lft forever
    inet6 fe80::42:e0ff:fe9e:7aab/64 scope link
       valid_lft forever preferred_lft forever

docker inspect mycontainer:

[
    {
        "Id": "801563c785e02550bd4f69cc768cf53829c816fca2c3210d28ab657f92bc1e2e",
        "Created": "2017-09-12T08:01:24.6470979Z",
        "Path": "/opt/IBM/WebSphere/AppServer/bin/startServer.sh",
        "Args": [
            "server1"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 64056,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2017-09-12T08:39:23.0578869Z",
            "FinishedAt": "2017-09-12T08:39:17.3321701Z"
        },
        "Image": "sha256:170f29ad73e6d24d562dec47f936caf54b9389eb7d0ca22853724942ae696c50",
        "ResolvConfPath": "/var/lib/docker/containers/801563c785e02550bd4f69cc768cf53829c816fca2c3210d28ab657f92bc1e2e/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/801563c785e02550bd4f69cc768cf53829c816fca2c3210d28ab657f92bc1e2e/hostname",
        "HostsPath": "/var/lib/docker/containers/801563c785e02550bd4f69cc768cf53829c816fca2c3210d28ab657f92bc1e2e/hosts",
        "LogPath": "/var/lib/docker/containers/801563c785e02550bd4f69cc768cf53829c816fca2c3210d28ab657f92bc1e2e/801563c785e02550bd4f69cc768cf53829c816fca2c3210d28ab657f92bc1e2e-json.log",
        "Name": "/mucontainer",
        "RestartCount": 0,
        "Driver": "overlay",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": [
                "/opt/DOCKER:/DEPLOY"
            ],
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "host",
            "PortBindings": {
                "1521/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "1521"
                    }
                ],
                "1522/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "1522"
                    }
                ],
                "9043/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "9043"
                    }
                ],
                "9060/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "9060"
                    }
                ],
                "9080/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "9080"
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DiskQuota": 0,
            "KernelMemory": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": -1,
            "OomKillDisable": false,
            "PidsLimit": 0,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0
        },
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay/3d2ed375c0d057e6dee49d0d1e521a2ab6bf8616e87940d3e8ae53346fb155ea/root",
                "MergedDir": "/var/lib/docker/overlay/51780db78931143df65f04408c0e4c6768a218be8b5ef5e6ea9914c98f15ebdb/merged",
                "UpperDir": "/var/lib/docker/overlay/51780db78931143df65f04408c0e4c6768a218be8b5ef5e6ea9914c98f15ebdb/upper",
                "WorkDir": "/var/lib/docker/overlay/51780db78931143df65f04408c0e4c6768a218be8b5ef5e6ea9914c98f15ebdb/work"
            },
            "Name": "overlay"
        },
        "Mounts": [
            {
                "Type": "bind",
                "Source": "/opt/DOCKER",
                "Destination": "/DEPLOY",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            }
        ],
        "Config": {
            "Hostname": "docker",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "1521/tcp": {},
                "1522/tcp": {},
                "2809/tcp": {},
                "443/tcp": {},
                "5060/tcp": {},
                "5061/tcp": {},
                "5558/tcp": {},
                "5578/tcp": {},
                "7276/tcp": {},
                "7286/tcp": {},
                "7777/tcp": {},
                "8880/tcp": {},
                "9043/tcp": {},
                "9060/tcp": {},
                "9080/tcp": {},
                "9082/tcp": {},
                "9100/tcp": {},
                "9353/tcp": {},
                "9401/tcp": {},
                "9402/tcp": {},
                "9403/tcp": {},
                "9443/tcp": {},
                "9633/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": null,
            "Image": "172.25.25.66:5000/uf/wasufbos:latest",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": [
                "/opt/IBM/WebSphere/AppServer/bin/startServer.sh",
                "server1"
            ],
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "77b4c453bd6adafd8e6dc2ba7b312aedce57f85d3f429216715150c3aafbd7d4",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "/var/run/docker/netns/default",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "host": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "4a7500c8681a70f1ea3779b6f64723144dcc49c365f96ce21dea8c1bd5af5172",
                    "EndpointID": "e5c55f584d19be55f2aee5dd6f5e831696d3063ff14d85742e95d28fc1a18cda",
                    "Gateway": "",
                    "IPAddress": "",
                    "IPPrefixLen": 0,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "",
                    "DriverOpts": null
                }
            }
        }
    }
]

Docker版本 17.06.0-ce,build 02c1d87

Linux CENTOS7 localhost.localdomain 3.10.0-514.el7.x86_64#1 SMP Tue 11月22日16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU / Linux

0 个答案:

没有答案