gpt4 book ai didi

amazon-web-services - Docker 容器无法连接到 Internet

转载 作者:行者123 更新时间:2023-12-02 18:45:18 24 4
gpt4 key购买 nike

我在 AWS EC2 实例上运行 Docker 容器,Docker 容器通过 Docker 网络连接,该网络通过 etcd 集群进行复制。但是所有的 Container 都无法连接到外部。例如,如果我对主机执行 ping 或 curl 操作,则会导致 100% 的包裹丢失。etcd 网络通过 AWS 私有(private) IP 进行通信。

这是我的 docker 信息:

root@ip-10-0-127-34:/home# docker info
Containers: 3
Running: 3
Paused: 0
Stopped: 0
Images: 9
Server Version: 17.05.0-ce
Storage Driver: devicemapper
Pool Name: docker-202:1-2050903-pool
Pool Blocksize: 65.54kB
Base Device Size: 10.74GB
Backing Filesystem: xfs
Data file: /dev/loop0
Metadata file: /dev/loop1
Data Space Used: 4.554GB
Data Space Total: 107.4GB
Data Space Available: 102.8GB
Metadata Space Used:sattler 6.922MB
Metadata Space Total: 2.147GB
Metadata Space Available: 2.141GB
Thin Pool Minimum Free Space: 3.221GB
Udev Sync Supported: true
Deferred Removal Enabled: false
Deferred Deletion Enabled: false
Deferred Deleted Device Count: 0
Data loop file: /var/lib/docker/devicemapper/devicemapper/data
Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
Library Version: 1.02.110 (2015-10-30)
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 9048e5e50717ea4497b757314bad98ea3763c145
runc version: 9c2d8d184e5da67c95d601382adf14862e4f2228
init version: 949e6fa
Security Options:
apparmor
seccomp
Profile: default
Kernel Version: 4.4.0-1028-aws
Operating System: Ubuntu 16.04.3 LTS
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 7.303GiB
Name: ip-10-0-127-34
ID: JFQO:C56I:VM22:UDKJ:QDKD:HUDT:KL3X:JCSR:WAPG:66JL:S4RM:4ENN
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Cluster Store: etcd://127.0.0.1:2379
Cluster Advertise: 10.0.127.34:2376
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false

WARNING: devicemapper: usage of loopback devices is strongly discouraged for production use.
Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.
WARNING: No swap limit support

Docker 检查网络:

     {
"Name": "df-global",
"Id": "59aef8ccc5d7464ee715428783b9b03ba7737d298f41cc30a21f4856e75b92c1",
"Created": "2017-08-14T09:51:31.650109966Z",
"Scope": "global",
"Driver": "overlay",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "192.168.1.0/14"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"Containers": {

"ep-f257d697653d801395f9154d086a6290694d6ded7aefe827c67dcd10808023eb": {
"Name": "elasticsearch-data-1",
"EndpointID": "f257d697653d801395f9154d086a6290694d6ded7aefe827c67dcd10808023eb",
"MacAddress": "02:42:c0:a8:00:0b",
"IPv4Address": "192.168.0.11/14",
"IPv6Address": ""
},
"ep-f5c1be7a768802154b58b33e67a3f009df1d4f1336297df9f914be9a720bd8ce": {
"Name": "postgresql-vg_internal01-prod",
"EndpointID": "f5c1be7a768802154b58b33e67a3f009df1d4f1336297df9f914be9a720bd8ce",
"MacAddress": "02:42:c0:a8:00:02",
"IPv4Address": "192.168.0.2/14",
"IPv6Address": ""

这里描述了同样的问题:https://forums.docker.com/t/ping-between-containers-on-different-docker-host-but-connected-by-overlay-networ-fails/9960但没有答案

最佳答案

在主机上运行:

sudo ip addr show docker0 

您将获得包含以下内容的输出:

inet 172.17.2.1/16 scope global docker0

docker 主机在 docker0 网络接口(interface)上的 IP 地址为 172.17.2.1。

然后启动容器:

docker run --rm -it ubuntu:trusty bash 

然后运行

ip addr show eth0

输出将包括:

inet 172.17.1.29/16 scope global eth0

您的容器的 IP 地址为 172.17.1.29。现在查看路由表:运行:

route

输出将包括:

Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 172.17.2.1 0.0.0.0 UG 0 0 0 eth0

这意味着 docker 主机 172.17.2.1 的 IP 地址被设置为默认路由,并且可以从您的容器访问。

现在尝试 ping 到您的主机 ip :

root@e21b5c211a0c:/# ping 172.17.2.1
PING 172.17.2.1 (172.17.2.1) 56(84) bytes of data.
64 bytes from 172.17.2.1: icmp_seq=1 ttl=64 time=0.071 ms
64 bytes from 172.17.2.1: icmp_seq=2 ttl=64 time=0.211 ms
64 bytes from 172.17.2.1: icmp_seq=3 ttl=64 time=0.166 ms

如果这很有效,您很可能可以 ping 通任何公共(public) IP

希望对您有所帮助!

关于amazon-web-services - Docker 容器无法连接到 Internet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45664226/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com