gcb-docker-compose icon indicating copy to clipboard operation
gcb-docker-compose copied to clipboard

Can't connect directly to redis from integration test

Open cesarvarela opened this issue 6 years ago • 4 comments

HI, I'm trying to connect directly to the redis server from the integration test by adding a container_name to the redis service in the compose yaml like this:

version: '2'

services:

  counter:
    image: gcr.io/${PROJECT_ID}/gcb-docker-compose:latest
    container_name: counter
    depends_on:
      - redis
    ports:
      - "50051:50051"
    environment:
      - REDIS_HOST=redis
      - REDIS_PORT=6379

  redis:
    container_name: redis
    image: redis
    ports:
      - "6379:6379"

networks:
    default:
        external:
            name: cloudbuild

And then doing in the integration test step:

const redisClient = redis.createClient({host: 'redis', port: '6379');

But I get an error in the cloud build console:

Step #2: (node:26) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 192.168.10.4:6379
Step #2:     at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1191:14)

Any idea why?

cesarvarela avatar May 30 '19 15:05 cesarvarela

Not sure, but what is this IP 192.168.10.4 ?

Philmod avatar May 30 '19 15:05 Philmod

I have no idea, that's what the cloud build console shows.

I'n another project that uses both mysql and redis, when running the integration tests:

when trying to connect to the mysql service:

Step #2:     connect ECONNREFUSED 192.168.10.4:5506

when trying to connect to the redis service:

Step #2: (node:26) UnhandledPromiseRejectionWarning: Error: connect ECONNREFUSED 192.168.10.3:5579

This other project also spins a node service with compose (like this repo), and connecting to that service from the integration test works (If I omit the protocol).

cesarvarela avatar May 30 '19 15:05 cesarvarela

Did you verify that the code from this repo works out of the box?

Philmod avatar May 30 '19 17:05 Philmod

Just did that, what isn't working is remapping ports in compose ports configuration: If I do this:

  redis:
    container_name: redis
    image: redis
    ports:
      - "7379:6379"

Then I get the weird IPs errors:

Step #4:      Uncaught Error: Redis connection to redis:7379 failed - connect ECONNREFUSED 192.168.10.3:7379

cesarvarela avatar May 30 '19 19:05 cesarvarela