2
respostas

Docker run --network host

Olá, estou tentando rodar os container na mesma rede do host mas me parece que assim que o container sobe, ele não consegue obter ip da rede.

Estou executando o seuinte comando

docker run --network host --name teste -p 80:80 -d -it henriqueweiand/micsrv:1.1 bash

A maquina sobe, acesso ela e starto o apache, dei um inspect mas não localizo ip dela... Ao executar

docker ps

A mesma esta ligada porem onde normalmente diz 0.0.0.0:80 -> 80 não esta exibindo nada.

Soluções?

2 respostas

Fala aí Henrique, blz?

Qual o resultado do ifconfig dentro do container? E qual o resultado do docker inspec teste?

Docker inspect

[
    {
        "Id": "fbfad78ac2b9357b52606fa4eb003b2effe6ccc75314df18173380e314c5f949",
        "Created": "2017-02-14T13:11:13.6049524Z",
        "Path": "bash",
        "Args": [],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 7018,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2017-02-14T13:11:14.5203899Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:0246e8f2d4c9e00996d2db733f36c07bf75da89e44dae1308ace05d3556f03be",
        "ResolvConfPath": "/var/lib/docker/containers/fbfad78ac2b9357b52606fa4eb003b2effe6ccc75314df18173380e314c5f949/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/fbfad78ac2b9357b52606fa4eb003b2effe6ccc75314df18173380e314c5f949/hostname",
        "HostsPath": "/var/lib/docker/containers/fbfad78ac2b9357b52606fa4eb003b2effe6ccc75314df18173380e314c5f949/hosts",
        "LogPath": "/var/lib/docker/containers/fbfad78ac2b9357b52606fa4eb003b2effe6ccc75314df18173380e314c5f949/fbfad78ac2b9357b52606fa4eb003b2effe6ccc75314df18173380e314c5f949-json.log",
        "Name": "/teste",
        "RestartCount": 0,
        "Driver": "overlay2",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "host",
            "PortBindings": {
                "80/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "80"
                    }
                ]
            },
            "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": [
                30,
                120
            ],
            "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": [],
            "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": {
            "Name": "overlay2",
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/0aa7a1a70ebc82ad0344d53d5bb61234d4541ce5d49392d564c6c01c5372bfe0-init/diff:/var/lib/docker/overlay2/47b086d726f93a403de41216898dc4118fab4f640b5cc49360aef0b0339bd5ca/diff:/var/lib/docker/overlay2/8fe4b11317124802e0307089b9aab38a82cc0c221f85a4c75076fc08575f980d/diff:/var/lib/docker/overlay2/233d3e750d92e7ab4988e46fea9e1065c51fa8a679c972cf58c33a4fc6cd29b7/diff:/var/lib/docker/overlay2/afd5343ea8e862f5ce0d540807d6a618677e053038f24653ac44e36d8a2a6202/diff:/var/lib/docker/overlay2/be678c97a7ce0e3a84164a6bb55927e89256da9c9656695dfb6de6acfa9b8d69/diff:/var/lib/docker/overlay2/1fd055c9b47d017900f7be12ae03f188f51e1d3e42ccc892bb5eda040d2bc13d/diff:/var/lib/docker/overlay2/6e3ff861547615b17a60a93233e7c32eb3c52050d8b39c6cd48a62f50061af22/diff:/var/lib/docker/overlay2/88a60925fe7e7c1e31f262a37ac04b0a2e81c56089f584f0d5d2ea8c2a754994/diff:/var/lib/docker/overlay2/82a94dda686e21a8f84bcb4a7846850da1dd6e208891d738cf5dee3141df837c/diff:/var/lib/docker/overlay2/db8b766d41f77fcc8c4edbb68b1432f0fcb8cb19f59174a567d0d11a5ffb4057/diff:/var/lib/docker/overlay2/f13854ad8a541ca78308ee6fafed5be08f203ec1843bb35a1b8b3c1812b48074/diff:/var/lib/docker/overlay2/dbaf2f946c05834930d4072881e8fd57792e5f485104741e8247884a2413b2be/diff:/var/lib/docker/overlay2/f23c4eac22b3e0138717aa904287f49982c48319e9d45f1a485e3c6903a5d5f5/diff:/var/lib/docker/overlay2/fd9ec5ad39dbfd424639170b1acb7c557ed621e9c574a56b70d3b5d51b81777e/diff",
                "MergedDir": "/var/lib/docker/overlay2/0aa7a1a70ebc82ad0344d53d5bb61234d4541ce5d49392d564c6c01c5372bfe0/merged",
                "UpperDir": "/var/lib/docker/overlay2/0aa7a1a70ebc82ad0344d53d5bb61234d4541ce5d49392d564c6c01c5372bfe0/diff",
                "WorkDir": "/var/lib/docker/overlay2/0aa7a1a70ebc82ad0344d53d5bb61234d4541ce5d49392d564c6c01c5372bfe0/work"
            }
        },
        "Mounts": [],
        "Config": {
            "Hostname": "moby",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "80/tcp": {}
            },
            "Tty": true,
            "OpenStdin": true,
            "StdinOnce": false,
            "Env": [
                "PATH=/composer/vendor/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "COMPOSER_HOME=/composer",
                "COMPOSER_ALLOW_SUPERUSER=1"
            ],
            "Cmd": [
                "bash"
            ],
            "Image": "henriqueweiand/micsrv:1.1",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "2a56e0da99ccb76c0e9e04e4186786ed29bd7ece112941874f104429ea2b493c",
            "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": "be4874cea10a458a8aaed3ddfd0fb184f94061b6568cc20e9b7d04cb42baa2fa",
                    "EndpointID": "629b60142040f21189878229680be0f18db2ffe5dda0a8ae2ebda7038eb39372",
                    "Gateway": "",
                    "IPAddress": "",
                    "IPPrefixLen": 0,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": ""
                }
            }
        }
    }
]

ifconfig

docker0   Link encap:Ethernet  HWaddr 02:42:71:a1:a6:be
          inet addr:172.17.0.1  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::42:71ff:fea1:a6be/64 Scope:Link
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:126 errors:0 dropped:0 overruns:0 frame:0
          TX packets:119 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:17297 (17.2 KB)  TX bytes:10125 (10.1 KB)

eth0      Link encap:Ethernet  HWaddr c0:ff:ee:c0:ff:ee
          inet addr:192.168.65.2  Bcast:192.168.65.7  Mask:255.255.255.248
          inet6 addr: fe80::8f05:9f1a:4975:9708/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:806 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3481 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:265293 (265.2 KB)  TX bytes:468726 (468.7 KB)

hvint0    Link encap:Ethernet  HWaddr 00:15:5d:21:01:01
          inet addr:10.0.75.2  Bcast:0.0.0.0  Mask:255.255.255.0
          inet6 addr: fe80::215:5dff:fe21:101/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:14938 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7973 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:2090806 (2.0 MB)  TX bytes:644674 (644.6 KB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:1751 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1751 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1
          RX bytes:31518 (31.5 KB)  TX bytes:31518 (31.5 KB)