Docker 호스트는 서로 통신하지 않습니다.

Docker 호스트는 서로 통신하지 않습니다.

Docker를 테스트 중이고 많은 문서를 검토했지만 여전히 모두 연결할 수 없습니다. 테스트할 쉘 스크립트가 있지만 이러한 실행 사이의 연결을 얻지 못했습니다.

$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

보시다시피 두 컴퓨터 모두에 루프를 만들고 시간이 다 될 때까지 실행되도록 했습니다. 하지만 개인 네트워크로 설정하거나 포트 포워딩을 하면 무엇을 테스트하든 상관없습니다. 이름 조회나 호스트에 대한 ping을 수행할 수 없습니다.

누군가 내가 뭘 잘못하고 있는지 지적할 수 있나요? 2~5일 전부터 이 문제를 해결하려고 노력했지만 더 이상 가까워지지 않습니다.

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

체크 출력입니다

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 ~ #

핑에서 이름 확인이 작동하고 있지만 패킷이 시스템 1에 도달하지 않는 것을 볼 수 있습니다.

답변1

명령은 모두 정확하지만 다음을 설정해야 합니다.

sysctl -w net.ipv4.ip_forward=1

그런 다음 docker 서비스를 다시 시작해야 합니다.

service docker restart

관련 정보