Search code examples
spring-bootdockerrediscontainers

Unable to connect from Spring Boot to Dockerized Redis in outside/inside machine


I am connecting to Redis from the spring boot app on the outside machine where the Redis server docker container is not running. When the app tries to connect to Redis, the app can't connect properly until the sent request is timed out. Meanwhile, if I try to connect from:

  1. Inside the machine where the Redis server docker container is running with the host is localhost, I could connect it. And, I don't know why I can't connect by setup host value as a numerical IP/alphabetical (URL), only works with "localhost."
  2. Outside machine where the Redis server docker container is not running with Redis client app GUI for management, I could connect it.

application.properties:

spring.redis.host=pc-1
spring.redis.port=6379

pc-1 is alias from some numerical ip. I'am using hosts feature from windows to aliasing/redirecting it.

.env:

REDIS_PORT=6379

docker-compose.yml:

  redis:
    image: redis:latest
    ports:
      - "${REDIS_PORT}:6379"
    command:
      # - redis-server
      # - --requirepass "${REDIS_PASSWORD}"
    networks:
      - redis
    healthcheck:
      test: ["CMD-SHELL", "redis-cli ping"]
      interval: 10s
      timeout: 10s
      retries: 3

I need help on this issue.

Update: I'm ignoring this question because it is currently not relevant to my work now. I suspect this is because of bugs or limited features in Docker Windows or WSL. Specifically, the numerical IP and alphabetical address I have used perhaps using the connection route to the router I have been using. Additionally, my machines are connected not only by just one adapter. So, the success of the connection might be random. When this question was asked initially, the WSL did not support a connection to the router. To support it, we need to enable the recent experimental mirrored networking feature.


Solution

  • I suspect this is because of bugs or limited features in Docker Windows or WSL. Specifically, the numerical IP and alphabetical address I have used perhaps using the connection route to the router I have been using. Additionally, my machines are connected not only by just one adapter. So, the success of the connection might be random. When this question was asked initially, the WSL did not support a connection to the router. To support it, we need to enable the recent experimental mirrored networking feature.

    Links: