'Unable to connect remotely with Redis based Nestjs microservice
I have a Redis based dockerized microservice that I have deployed on a vps. In main.ts, this is how the service is exposed:
const app = await NestFactory.createMicroservice(AppModule, {
transport: Transport.REDIS,
options: {
url: "redis://redis:6379"
}
});
await app.listen();
The redis is the service name within the docker-compose.yml
I have it deployed on vps and it runs fine and I can ping/telnet to the server
The client app is a regular dockerized NestJS app that tries to connect to the microservice in the following way:
ClientsModule.registerAsync([{
name: "PAIGHAM_SERVICE",
imports: [ConfigModule],
useFactory: (configService: ConfigService) => ({
transport: Transport.REDIS,
options: {
url: "redis://[IP-ADDRESS]:6379"
}
}),
inject: [ConfigService]
}])
The IP_ADDRESS is the external IP assigned to the VPS hosting the microservice
But the client is unable to connect to the service. I also health-checked but it times out:
return this.health.check([
() => this.microservice.pingCheck<RedisOptions>("service", {
transport: Transport.REDIS,
options: {
url: "redis://207.180.210.3:6379"
}
})
])
I have no clue what wrong I am doing. Any immediate help would be highly appreciated.
UPDATE: This is doker-compose.yml for the microservice:
version: "3.5"
services:
service:
build:
context: ../
dockerfile: ./docker/service/Dockerfile
volumes:
- "${API_FOLDER_PATH}/src:/app/src"
networks:
- paigham-network
db:
build:
context: ../
dockerfile: ./docker/db/Dockerfile
restart: always
volumes:
- db-data:/var/lib/postgresql/data
environment:
POSGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: paigham
ports:
- 5432:5400
networks:
- paigham-network
redis:
image: "redis:alpine"
command: [ "redis-server", "--bind", "0.0.0.0", "--port", "6379" ]
environment:
- ALLOW_EMPTY_PASSWORD=yes
volumes:
- cache:/data
ports:
- 6379:6379
networks:
- paigham-network
redis-commander:
image: rediscommander/redis-commander:latest
restart: always
environment:
- REDIS_HOSTS=local:redis:6379
ports:
- 8089:8081
networks:
- paigham-network
networks:
paigham-network:
external: false
volumes:
db-data:
cache:
driver: local
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
