Reputation: 105
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
Upvotes: 4
Views: 7729
Reputation: 3677
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.
Upvotes: 2