Talking to Nest.js microservice over tcp in docker-compose
As this issue (this comment) explains
If no host is specified, NestJS will bind to localhost
This caused me to be unable to connect with the service while it was running in docker. So by setting the host to 0.0.0.0
I was able to connect over TCP.
Full example:
const app = await NestFactory.createMicroservice(AppModule, { transport: Transport.TCP, options: { host: '0.0.0.0', port: 3000 }});
try adding this to your compose:
myservice: expose: - "3000" ports: - "3000:3000"