<p>I have the following docker file:</p>

<pre><code>FROM openjdk:8-jdk-alpine
ENV PORT 8094
EXPOSE 8094
RUN mkdir -p /app/
COPY build/libs/fqdn-cache-service.jar /app/fqdn-cache-service.jar
WORKDIR /build
ENTRYPOINT [ "sh" "-c", "java -jar /app/fqdn-cache-service.jar" ]
</code></pre>

<p>docker-compose.yaml file:</p>

<pre><code>version: '3'
services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    image: fqdn-cache-service
    ports:
      - "8094:8094"
    links:
      - "db:redis"
  db:
    image: "redis:alpine"
    #hostname: redis
    ports:
      - "6378:6378"
</code></pre>

<p>deployment.yaml file</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: fqdn-cache-service
spec:
  selector:
    matchLabels:
      run: spike
  replicas: 1
  template:
    metadata:
      labels:
        app: redis
        run: spike
    spec:
      containers:
        - name: fqdn-cache-service
          imagePullPolicy: Never
          image: fqdn-cache-service:latest
          ports:
            - containerPort: 8094
              protocol: TCP
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: redis
spec:
  selector:
    matchLabels:
      run: spike
  replicas: 1
  template:
    metadata:
      labels:
        run: spike
    spec:
      hostname: redis
      containers:
        - name: redis
          image: redis:alpine
          ports:
            - containerPort: 6379
---
apiVersion: v1
kind: Service
metadata:
  name: fqdn-cache-service
  labels:
    run: spike
spec:
  type: NodePort
  ports:
    - port: 8094
      nodePort: 30001
  selector:
    run: spike
---
apiVersion: v1
kind: Service
metadata:
  name: redis
  labels:
    run: spike
    app: redis
spec:
  type: NodePort
  ports:
    - port: 6379
      nodePort: 30002
  selector:
    run: spike
</code></pre>

<p>And the cluster info ip is 127.0.0.1.
I'm using microk8s over ubuntu OS.
If I request for get by and ID (127.0.0.1/webapi/users/1) I get the error:</p>

<pre><code>Cannot get Jedis connection; nested exception is redis.clients.jedis.exceptions.JedisConnectionException: Could not get a resource from the pool
</code></pre>

<p>Although on regular java application with redis or dockerize spring boot with redis it's working.</p>

<p>Any help why this is happened?</p>

<p>This is the configuration of the spring boot:</p>

<pre><code>@Configuration
public class ApplicationConfig {
    @Bean
    JedisConnectionFactory jedisConnectionFactory() {
        JedisConnectionFactory factory = new JedisConnectionFactory();
        factory.setHostName("127.0.0.1");
        factory.setPort(30001);
        factory.setUsePool(true);
        return factory;
    }

    @Bean
    RedisTemplate redisTemplate() {
        RedisTemplate&lt;String, FqdnMapping&gt; redisTemplate = new RedisTemplate&lt;String, FqdnMapping&gt;();
        redisTemplate.setConnectionFactory(jedisConnectionFactory());
        return redisTemplate;
    }
}
</code></pre>

<p>The issue also happenes if the host name is localhost and\or the port is 6379...</p>

<p>Thanks!</p>

Shay Zambrovski
<p>When you're running in a container, 127.0.0.1 usually refers to the container itself, not to the host the container is running on. If you're trying to connect to a service, try using its name and port: "redis" on port 6379 and "fqdn-cache-service" on 8094.</p>
