我的应用程序依赖于 Cassandra,所以我将它们全部放在 docker-compose 文件中,现在只需使用此处给出的普通 docker,我就可以在本地正常运行它,但是当我尝试在 compose 中使用相同的配置时,我不断出现错误
顶部堆栈跟踪:
[s0] Error connecting to Node(endPoint=localhost/127.0.0.1:9042, hostId=null, hashCode=8a90356), trying next node (ConnectionInitException: [s0|control|connecting...] Protocol initialization request, step 1 (OPTIONS): failed to send request (io.netty.channel.StacklessClosedChannelException))
结束:
Suppressed: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: localhost/127.0.0.1:9042
Caused by: java.net.ConnectException: Connection refused
at java.base/sun.nio.ch.Net.pollConnect(Native Method)
at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:672)
at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:946)
at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:337)
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:334)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:776)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: io.netty.channel.StacklessClosedChannelException: null
at io.netty.channel.AbstractChannel$AbstractUnsafe.flush0()(Unknown Source)
我的docker-compose:
version: "3.8"
services:
urls-storage:
image: cassandra:latest
container_name: urls-storage-db
command: [ -f ]
environment:
CASSANDRA_CLUSTER_NAME: app
ports:
- "9042:9042"
- "9160:9160"
- "7199:7199"
healthcheck:
test: [ "CMD-SHELL", "[ $$(nodetool statusgossip) = running ]" ]
interval: 10s
timeout: 5s
retries: 3
volumes:
- cassandra_data:/var/lib/cassandra
app:
build: .
container_name: url-shortener-service
ports:
- '8083:8083'
depends_on:
urls-storage:
condition: service_healthy
volumes:
cassandra_data:
driver: local
application.yaml:
server:
port: 8083
spring:
application:
name: url-shortener-service
cassandra:
port: 9042
keyspace-name: links
schema-action: create-if-not-exists
connection:
connect-timeout: 30s
init-query-timeout: 10s
request:
timeout: 10s
contact-points: urls-storage-db
local-datacenter: datacenter1
我什至尝试对接触点进行硬编码,但无济于事,我可以访问撰写容器中的 cassandra,但我的应用程序似乎无法访问它。
cassandra
不应该是数据属性吗?路径中应该有数据,不是吗?localhost:9042
,这是错误的,因为它应该是 cassandra 容器的主机名,是吗?应仔细检查您的接触点设置