I have a spring boot rest service running on windows 10 machine and I have Redis running on a docker container. Now, I want my Spring Boot to connect to the redis container, however, it is always giving me the following error:
java.net.UnknownHostException: redis
My application.properties, contains the following:
# Set Redis server and Jedis settings
spring.redis.host = redis
spring.redis.port = 6379
spring.redis.password = test123
spring.jedis.connection.timeout = 60
and this is my docker-compose.yml:
version: '2'
networks:
app-tier:
driver: bridge
services:
redis:
image: 'bitnami/redis:latest'
container_name: 'redis-cache'
environment:
- REDIS_PASSWORD=test123
- REDIS_DISABLE_COMMANDS=FLUSHDB,FLUSHALL
labels:
kompose.service.type: nodeport
ports:
- '6379:6379'
volumes:
- 'redis_data:/bitnami/redis'
networks:
- app-tier
volumes:
redis_data:
driver: local
Please set spring.redis.host = localhost in application.properties.
Since the current value set is 'redis', application is not able to find this host and hence you are getting unknownhost exception.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With