Can't connect directly to redis from integration test
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?
Not sure, but what is this IP 192.168.10.4 ?
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).
Did you verify that the code from this repo works out of the box?
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