Ich bin sicher, dass sich alle Container im selben Netzwerk befinden.
Ich kann mit redis-cli eine Verbindung zu redisContainer herstellen
Wenn ich meine Spring-Boot-App von der IDE aus starte (nicht im Docker-Container), alles in Ordnung
Ich erhalte nur diese Fehlermeldung unten, ohne besondere Erklärungen
Ich bin sicher, dass die Spring Boot-App korrekt empfangen wird env-Variablen aus der Compose-Datei
Ich habe es versucht Entfernen Sie „hosts:“ aus dem Redis-Container. Ich habe versucht, REDIS_HOST im Backend-Container auf localhost zu setzen
version: '3.8'
services:
db:
image: postgres:latest
container_name: postgresql_container
environment:
POSTGRES_DB: insight
POSTGRES_USER: admin
POSTGRES_PASSWORD: admin
ports:
- "15432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
restart: always
redis:
image: redis:latest
container_name: redisContainer
ports:
- "6379:6379"
backend:
build: .
container_name: backendContainer
ports:
- "8081:8082"
environment:
REDIS_PORT: 6379
REDIS_HOST: redis
SPRING_DATASOURCE_URL: jdbc:postgresql://db:5432/insight
SPRING_DATASOURCE_USERNAME: admin
SPRING_DATASOURCE_PASSWORD: admin
depends_on:
- db
restart: always
volumes:
postgres_data:
application.yaml
spring:
datasource:
driver-class-name: org.postgresql.Driver
url: ${SPRING_DATASOURCE_URL}
username: ${SPRING_DATASOURCE_USERNAME}
password: ${SPRING_DATASOURCE_PASSWORD}
jpa:
show-sql: true
hibernate:
ddl-auto: update
database-platform: org.hibernate.dialect.PostgreSQLDialect
redis:
host: ${REDIS_HOST}
port: ${REDIS_PORT}
server:
port: 8082
logging:
level:
org.springframework.data.redis: DEBUG
Die Fehlermeldung:
2024-12-23 18:36:48 2024-12-23T15:36:48.226Z ERROR 1 --- [nio-8082-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet
[dispatcherServlet] in context with path [] threw exception [Request processing failed: org.springframework.data.redis.RedisConnectionFailureException:
Unable to connect to Redis] with root cause
2024-12-23 18:36:48
2024-12-23 18:36:48 java.net.ConnectException: Connection refused
2024-12-23 18:36:48 at java.base/sun.nio.ch.Net.pollConnect(Native Method) ~[na:na]
2024-12-23 18:36:48 at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:672) ~[na:na]
2024-12-23 18:36:48 at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:946) ~[na:na]
2024-12-23 18:36:48 at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:336) ~[netty-transport-4.1.114.Final.jar!/:4.1.114.Final]
2024-12-23 18:36:48 at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:339) ~[netty-transport-4.1.114.Final.jar!/:4.1.114.Final]
2024-12-23 18:36:48 at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:776) ~[netty-transport-4.1.114.Final.jar!/:4.1.114.Final]
2024-12-23 18:36:48 at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724) ~[netty-transport-4.1.114.Final.jar!/:4.1.114.Final]
2024-12-23 18:36:48 at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650) ~[netty-transport-4.1.114.Final.jar!/:4.1.114.Final]
2024-12-23 18:36:48 at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562) ~[netty-transport-4.1.114.Final.jar!/:4.1.114.Final]
2024-12-23 18:36:48 at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[netty-common-4.1.114.Final.jar!/:4.1.114.Final]
2024-12-23 18:36:48 at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.114.Final.jar!/:4.1.114.Final]
2024-12-23 18:36:48 at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.114.Final.jar!/:4.1.114.Final]
2024-12-23 18:36:48 at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
2024-12-23 18:36:48
Ich habe diese beiden Abhängigkeiten zu Redis
org.springframework.boot
spring-boot-starter-data-redis
org.springframework.boot
spring-boot-starter-cache
Ich habe keine Redis-Konfigurationen, die App funktioniert gut mit Redis, wenn sie nicht aus dem Container gestartet wird
Der Spring-Boot-Backend-Container kann in Docker Compose intern keine Verbindung zum Redis-Container herstellen ⇐ Java
-
- Similar Topics
- Replies
- Views
- Last post