docker - 为什么我看到 host.docker.internal 的两个不同值以及为什么 cassandra 容器无法绑定到它
问题描述
我想运行 Cassandra Docker 映像。我希望我的应用程序(在另一个容器中运行)可以连接到 Cassandra 容器。所以我想host.docker.internal
在这两个应用程序中都用作域名。
当我启动 Cassandra 映像时,出现错误
org.apache.cassandra.exceptions.ConfigurationException: Unable to bind to address host.docker.internal/192.168.65.2:7000. Set listen_address in cassandra.yaml to an interface you can bind to, e.g., your private IP address on EC2
为什么要host.docker.internal
解决192.168.65.2/7000
?不应该192.168.1.12
是我etc/hosts
在 Windows 10 上的文件中配置的内容。
C:\Users\manuc>ping host.docker.internal
Pinging host.docker.internal [192.168.1.12] with 32 bytes of data:
Reply from 192.168.1.12: bytes=32 time<1ms TTL=128
Reply from 192.168.1.12: bytes=32 time=1ms TTL=128
Reply from 192.168.1.12: bytes=32 time<1ms TTL=128
Reply from 192.168.1.12: bytes=32 time<1ms TTL=128
192.168.1.12
我也尝试在启动 Cassandra 图像时明确指定,但我得到了类似的错误。
我能够启动容器的唯一方法是运行docker run ca795bbd8fd7
,但在这种情况下,Cassandra 在地址处侦听,Starting listening for CQL clients on /0.0.0.0:9042 (unencrypted)..
但cqlsh
我的其他 Docker 应用程序无法与其连接(在同一台 Windows 机器上运行)
尝试从容器外部连接到 Cassandra 容器
C:\Users\manuc>cqlsh host.docker.internal 9042
Connection error: ('Unable to connect to any servers', {'192.168.1.12': error(10061, "Tried connecting to [('192.168.1.12', 9042)]. Last error: No connection could be made because the target machine actively refused it")})
C:\Users\manuc>cqlsh 0.0.0.0 9042
Connection error: ('Unable to connect to any servers', {'0.0.0.0': error(10049, "Tried connecting to [('0.0.0.0', 9042)]. Last error: The requested address is not valid in its context")})
试图连接我的另一个容器
[trace] s.d.c.CassandraConnectionManagementService - creating session with uri CassandraConnectionUri(cassandra://host.docker.internal:9042/codingjedi) and cluster name Test Cluster
[trace] s.d.c.CassandraConnectionManagementService - exception in connecting with database com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s) tried for query failed (tried: host.docker.internal/192.168.65.2:9042 (com.datastax.driver.core.exceptions.TransportException: [host.docker.internal/192.168.65.2:9042] Cannot connect))
Oops, cannot start the server.
play.api.libs.json.JsResult$Exception: {"obj":[{"msg":["Unable to connect with database"],"args":[]}]}
(虽然我注意到这个容器也docker.internal.hosts
映射到与 Cassandra 容器相同的 IP 地址)。
附加信息。如果在没有 的情况下运行LISTENING_ADDRESS
,Cassandra 会公开以下端口
7000-7001/tcp, 7199/tcp, 9042/tcp, 9160/tcp
解决方案
这个问题很琐碎。启动时我没有暴露9042
端口cassandra
container
。这使事情开箱即用 -docker run -p 9042:9042 image_id
推荐阅读
- react-native - 更新 pod 后,我收到此错误。无效的 UIAccessibilityTraits '选项卡'
- git - 在 2 个分支/提交之间逐个文件检查差异文件的最佳方法?
- c# - 在匿名类型数组中包含空值/默认值的更简洁方法?
- python - 尝试在 tkinter 画布中显示图像时出错
- google-cloud-platform - 创建 TPU 时出错:“不能低于现有策略版本”
- html - 为什么当我将鼠标悬停在图像 div 上时我的图像会抖动
- php - 如何在 wordpress 中获取行数?
- java - 我如何编写“If/else Statement”来为用户提供答案?
- php - 使用 php 和 mysql 计算总值而不是行
- google-sheets - 检查名称以在选项卡上导入值