为什么我会看到host.docker.internal的两个不同值,以及为什么cassandra容器无法绑定到它

问题描述 投票:1回答:1

我想运行cassandra docker图像。我希望我的应用程序(在另一个container中运行)可以连接到cassandra容器。因此,我想在两个应用程序中都使用host.docker.internal作为域名。

[启动cassandra image时出现错误

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时显式指定images,但出现类似错误。

我能够启动容器的唯一方法是通过运行docker run ca795bbd8fd7,但是在这种情况下,cassandra在地址Starting listening for CQL clients on /0.0.0.0:9042 (unencrypted)..上监听cqlsh,但是我的其他docker应用程序无法与其连接(在同一台windows计算机上运行)

试图从容器外部连接到cassandra container

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")})

试图连接我的其他container

[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 container相同的IP地址>

附加信息如果运行时没有LISTENING_ADDRESS,则cassandra公开以下端口

7000-7001/tcp, 7199/tcp, 9042/tcp, 9160/tcp 

我想运行cassandra docker映像。我希望我的应用程序(在另一个容器中运行)可以连接到cassandra容器。因此,我想使用host.docker.internal作为....>

这个问题很琐碎。启动9042 cassandra时,我没有暴露container端口。这使事情开箱即用-docker run -p 9042:9042 image_id

docker cassandra-3.0
1个回答
0
投票

这个问题很琐碎。启动9042 cassandra时,我没有暴露container端口。这使事情开箱即用-docker run -p 9042:9042 image_id

© www.soinside.com 2019 - 2024. All rights reserved.