从 Docker 容器内部 Curl 到主机和端口不起作用

从 Docker 容器内部 Curl 到主机和端口不起作用

以下是容器:

CONTAINER ID        IMAGE                      COMMAND                  CREATED             STATUS              PORTS                                            NAMES
7ba94a1bd249        docker-elk_kibana          "/usr/local/bin/dumb…"   27 minutes ago      Up 27 minutes       0.0.0.0:5601->5601/tcp                           docker-elk_kibana_1
267c7f8136a8        docker-elk_elasticsearch   "/tini -- /usr/local…"   27 minutes ago      Up 27 minutes       0.0.0.0:9200->9200/tcp, 0.0.0.0:9300->9300/tcp   elasticsearch

从容器内部运行 curl:

bash-4.2$ curl -v http://10.206.2.97:9200
* About to connect() to 10.206.2.97 port 9200 (#0)
*   Trying 10.206.2.97...
* No route to host
* Failed connect to 10.206.2.97:9200; No route to host
* Closing connection 0
curl: (7) Failed connect to 10.206.2.97:9200; No route to host

从连接良好的主机运行相同的 curl:

[root@pla11010 docker-elk]# curl -v http://10.206.2.97:9200
* Rebuilt URL to: http://10.206.2.97:9200/
*   Trying 10.206.2.97...
* TCP_NODELAY set
* Connected to 10.206.2.97 (10.206.2.97) port 9200 (#0)
> GET / HTTP/1.1
> Host: 10.206.2.97:9200
> User-Agent: curl/7.61.1
> Accept: */*
>
< HTTP/1.1 200 OK
< content-type: application/json; charset=UTF-8
< content-length: 541

问题是,从 docker 容器内部,无法通过 curl 连接到主机和端口 9200。

[root@pla11010 docker-elk]# getenforce
Permissive


[root@pla11010 docker-elk]# cat /etc/os-release
NAME="Red Hat Enterprise Linux"
VERSION="8.0 (Ootpa)"
ID="rhel"
ID_LIKE="fedora"
VERSION_ID="8.0"
PLATFORM_ID="platform:el8"
PRETTY_NAME="Red Hat Enterprise Linux 8.0 (Ootpa)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:redhat:enterprise_linux:8.0:GA"
HOME_URL="https://www.redhat.com/"
BUG_REPORT_URL="https://bugzilla.redhat.com/"

REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 8"
REDHAT_BUGZILLA_PRODUCT_VERSION=8.0
REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="8.0"

防火墙已禁用。并且 ping 主机在容器内正常工作。请告诉我从容器内部连接到主机和端口会出现什么问题?

相关内容