Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2204

Connection refused: localhost/127.0.0.1:6379 (Redis) Spring boot with docker compose

$
0
0

I'm trying to dockerize a project that uses Redis. I have a spring boot application that uses Redis and wants to connect to it but it can't and getting below exception

org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis

It follows

application  | Caused by: io.lettuce.core.RedisConnectionException: Unable to connect to localhost/<unresolved>:6379application  |  at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:78)application  |  at io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:56)application  |  at io.lettuce.core.AbstractRedisClient.getConnection(AbstractRedisClient.java:350)application  |  at io.lettuce.core.RedisClient.connect(RedisClient.java:216)application  |  at org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.lambda$getConnection$1(StandaloneConnectionProvider.java:112)application  |  at java.base/java.util.Optional.orElseGet(Unknown Source)application  |  at org.springframework.data.redis.connection.lettuce.StandaloneConnectionProvider.getConnection(StandaloneConnectionProvider.java:112)application  |  at org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory$ExceptionTranslatingConnectionProvider.getConnection(LettuceConnectionFactory.java:1734)application  |  ... 296 common frames omittedapplication  | Caused by: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: localhost/127.0.0.1:6379application  | Caused by: java.net.ConnectException: Connection refusedapplication  |  at java.base/sun.nio.ch.Net.pollConnect(Native Method)application  |  at java.base/sun.nio.ch.Net.pollConnectNow(Unknown Source)application  |  at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(Unknown Source)application  |  at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:337)application  |  at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:334)application  |  at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:776)application  |  at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)application  |  at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)application  |  at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)application  |  at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)application  |  at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)application  |  at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)application  |  at java.base/java.lang.Thread.run(Unknown Source)

Here is my compose.yaml file.

services:  application:    build:      context: .      dockerfile: Dockerfile    image: 'vehicle-tracker'    container_name: 'application'    ports:      - '8080:8080'    networks:      - network    depends_on:      - redis  redis:    container_name: 'redis'    image: 'redis'    ports:      - '6379:6379'    networks:      - networknetworks:  network:    name: 'vehicle-tracker-network'    driver: bridge

and application.properties

#Server Configserver.port=8080# Cachespring.cache.type=redis# Redisspring.data.redis.host=redis

Obviously, the local IP of the container changes every time.

For example when I trydocker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' redis I get 172.18.0.2.

But with any changes, spring boot still tries to connect to localhost/127.0.0.1. I don't know what to do.


Viewing all articles
Browse latest Browse all 2204

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>