O Docker não se comunica entre si

1

Estou testando o docker e estava passando por muitas documentações, mas ainda não consegui conectá-las. Eu tenho um script de shell para testá-lo, mas não obtenho a conexão entre os que estão sendo executados.

$MAXTESTTIME=180
MACHINE1=$(docker run --net="testnet" -h MACHINE1 --name MACHINE1 -p 10080:80 -v /root/testcontent:/var/www/html:ro --cpuset-cpus="3-9" --memory="2G" -d ubuntu /bin/bash -c "sleep 120")
MACHINE2=$(docker run --net="testnet" -h MACHINE2 --link MACHINE1:MACHINE1 --name MACHINE2 -v /root/testcontent:/var/www/html:ro --cpuset-cpus="10-11" --memory="2G" -d ubuntu /bin/bash -c "apt-get -y update && apt-get -y install apt-utils iputils-ping && ping -c 2 MACHINE1 && ping -c 2 8.8.8.8 && ping -c 2 www.google.com")

docker network create testnet
sleep 2


docker start $MACHINE1 && sleep 1 && docker start $MACHINE2 &  sleep $MAXTESTTIME; docker stop $MACHINE1 & docker stop $MACHINE2

Como você pode ver, criei um loop em ambas as máquinas para deixá-las rodar até o tempo acabar. Mas não importa o que eu teste, se eu configurá-los para uma rede privada ou se eu fizer um encaminhamento de porta. Eles nunca são capazes de fazer uma pesquisa de nome ou executar ping no host.

Alguém pode me apontar na direção do que estou fazendo de errado? Estou tentando resolvê-lo desde 2, 5 dias e não me aproximo.

Containers: 2
 Running: 2
 Paused: 0
 Stopped: 0
Images: 4
Server Version: 1.12.1
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 11
 Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host overlay null
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Security Options: apparmor seccomp
Kernel Version: 4.4.0-31-generic
Operating System: Ubuntu 16.04.1 LTS
OSType: linux
Architecture: x86_64
CPUs: 12
Total Memory: 125.9 GiB
Name: xxxxxx.li
ID: xxxxxxxxxxxxx
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
WARNING: No swap limit support
Insecure Registries:
 127.0.0.0/8

Aqui está a saída de inspeção

root@monster ~ # docker inspect MACHINE1
[
    {
        "Id": "81f21a696a290813e32ee12af981453cfe29b26cdef809712dbbc4b77506e57c",
        "Created": "2016-08-21T18:05:16.3526528Z",
        "Path": "/bin/bash",
        "Args": [
            "-c",
            "apt-get update \u0026\u0026 apt-get -y upgrade \u0026\u0026 apt-get -y install apache2 \u0026\u0026 systemctl restart apache2 \u0026\u0026 systemctl start apache2 \u0026\u0026 while sleep 5; do echo blah; done"
        ],
        "State": {
            "Status": "exited",
            "Running": false,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 0,
            "ExitCode": 1,
            "Error": "",
            "StartedAt": "2016-08-21T18:05:16.672425325Z",
            "FinishedAt": "2016-08-21T18:05:40.466207063Z"
        },
        "Image": "sha256:f8d79ba03c00bbcd8079cf05b7526ac8f4f422744aad8c3747a29a38ed8c4a41",
        "ResolvConfPath": "/var/lib/docker/containers/81f21a696a290813e32ee12af981453cfe29b26cdef809712dbbc4b77506e57c/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/81f21a696a290813e32ee12af981453cfe29b26cdef809712dbbc4b77506e57c/hostname",
        "HostsPath": "/var/lib/docker/containers/81f21a696a290813e32ee12af981453cfe29b26cdef809712dbbc4b77506e57c/hosts",
        "LogPath": "/var/lib/docker/containers/81f21a696a290813e32ee12af981453cfe29b26cdef809712dbbc4b77506e57c/81f21a696a290813e32ee12af981453cfe29b26cdef809712dbbc4b77506e57c-json.log",
        "Name": "/MACHINE1",
        "RestartCount": 0,
        "Driver": "aufs",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": [
                "/root/testcontent:/var/www/html:ro"
            ],
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "testnet",
            "PortBindings": {
                "80/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "10080"
                    }
                ]
            },
            "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": 12884901888,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpusetCpus": "3-9",
            "CpusetMems": "",
            "Devices": [],
            "DiskQuota": 0,
            "KernelMemory": 0,
            "MemoryReservation": 0,
            "MemorySwap": -1,
            "MemorySwappiness": -1,
            "OomKillDisable": false,
            "PidsLimit": 0,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0
        },
        "GraphDriver": {
            "Name": "aufs",
            "Data": null
        },
        "Mounts": [
            {
                "Source": "/root/testcontent",
                "Destination": "/var/www/html",
                "Mode": "ro",
                "RW": false,
                "Propagation": "rprivate"
            }
        ],
        "Config": {
            "Hostname": "MACHINE1",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "80/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "/bin/bash",
                "-c",
                "apt-get update \u0026\u0026 apt-get -y upgrade \u0026\u0026 apt-get -y install apache2 \u0026\u0026 systemctl restart apache2 \u0026\u0026 systemctl start apache2 \u0026\u0026 while sleep 5; do echo blah; done"
            ],
            "Image": "ubuntu",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "b5165f66d0a487ddb8ff33fc4a9cd078f67b8cccb3a34bc6473d411cca9e5d77",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": null,
            "SandboxKey": "/var/run/docker/netns/b5165f66d0a4",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "testnet": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": [
                        "81f21a696a29"
                    ],
                    "NetworkID": "a2c25f900d0b2fe4f8a8e5f1b564d4bac107af4a0e2ab6bfbd8c72d7c009a0d2",
                    "EndpointID": "",
                    "Gateway": "",
                    "IPAddress": "",
                    "IPPrefixLen": 0,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": ""
                }
            }
        }
    }
]
root@monster ~ # docker inspect MACHINE2
[
    {
        "Id": "21d8fefb2bd3b8665d6aacaecb38ff554a06f5f433129104ab97f318e3ad8168",
        "Created": "2016-08-21T18:05:16.69206676Z",
        "Path": "/bin/bash",
        "Args": [
            "-c",
            "apt-get -y update \u0026\u0026 apt-get -y install apt-utils iputils-ping wget curl git netcat \u0026\u0026 while sleep 1; do ping -c 3 MACHINE1 \u0026\u0026 curl http://MACHINE1:80 \u0026\u0026 curl http://MACHINE1:10080 ; done"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 25612,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2016-08-21T18:05:16.990214383Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:f8d79ba03c00bbcd8079cf05b7526ac8f4f422744aad8c3747a29a38ed8c4a41",
        "ResolvConfPath": "/var/lib/docker/containers/21d8fefb2bd3b8665d6aacaecb38ff554a06f5f433129104ab97f318e3ad8168/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/21d8fefb2bd3b8665d6aacaecb38ff554a06f5f433129104ab97f318e3ad8168/hostname",
        "HostsPath": "/var/lib/docker/containers/21d8fefb2bd3b8665d6aacaecb38ff554a06f5f433129104ab97f318e3ad8168/hosts",
        "LogPath": "/var/lib/docker/containers/21d8fefb2bd3b8665d6aacaecb38ff554a06f5f433129104ab97f318e3ad8168/21d8fefb2bd3b8665d6aacaecb38ff554a06f5f433129104ab97f318e3ad8168-json.log",
        "Name": "/MACHINE2",
        "RestartCount": 0,
        "Driver": "aufs",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": [
                "/root/testcontent:/var/www/html:ro"
            ],
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "testnet",
            "PortBindings": {},
            "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": 12884901888,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpusetCpus": "10-11",
            "CpusetMems": "",
            "Devices": [],
            "DiskQuota": 0,
            "KernelMemory": 0,
            "MemoryReservation": 0,
            "MemorySwap": -1,
            "MemorySwappiness": -1,
            "OomKillDisable": false,
            "PidsLimit": 0,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0
        },
        "GraphDriver": {
            "Name": "aufs",
            "Data": null
        },
        "Mounts": [
            {
                "Source": "/root/testcontent",
                "Destination": "/var/www/html",
                "Mode": "ro",
                "RW": false,
                "Propagation": "rprivate"
            }
        ],
        "Config": {
            "Hostname": "MACHINE2",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "/bin/bash",
                "-c",
                "apt-get -y update \u0026\u0026 apt-get -y install apt-utils iputils-ping wget curl git netcat \u0026\u0026 while sleep 1; do ping -c 3 MACHINE1 \u0026\u0026 curl http://MACHINE1:80 \u0026\u0026 curl http://MACHINE1:10080 ; done"
            ],
            "Image": "ubuntu",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "49d4c262db743f5e95396ef0939afc069f725c73d3b7ada4682b7103e099f7c0",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "/var/run/docker/netns/49d4c262db74",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "testnet": {
                    "IPAMConfig": null,
                    "Links": [
                        "MACHINE1:MACHINE1"
                    ],
                    "Aliases": [
                        "21d8fefb2bd3"
                    ],
                    "NetworkID": "a2c25f900d0b2fe4f8a8e5f1b564d4bac107af4a0e2ab6bfbd8c72d7c009a0d2",
                    "EndpointID": "bf5e1d75206f997c946f299c3901a133001f309e5f1da382c6e292049ff29d58",
                    "Gateway": "192.168.0.1",
                    "IPAddress": "192.168.0.3",
                    "IPPrefixLen": 24,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:c0:a8:00:03"
                }
            }
        }
    }
]
root@monster ~ #

No ping, vejo que a resolução de nomes está funcionando, mas os pacotes não chegam na máquina 1.

    
por snapo 21.08.2016 / 20:03

1 resposta

0

Os comandos estavam todos corretos, mas eu tive que definir:

sysctl -w net.ipv4.ip_forward=1

você precisa reiniciar o serviço de encaixe

service docker restart
    
por 22.08.2016 / 20:47