I'm trying to communicate my microservices using rabbitmq(a docker container of that service). So every time I run my app it deliver
[Nest] 18 - 04/12/2025, 12:58:29 PM LOG [NestFactory] Starting Nest application...
[Nest] 18 - 04/12/2025, 12:58:29 PM LOG [InstanceLoader] AppModule dependencies initialized +5ms
[Nest] 18 - 04/12/2025, 12:58:29 PM LOG [InstanceLoader] ClientsModule dependencies initialized +0ms
[Nest] 18 - 04/12/2025, 12:58:29 PM ERROR [Server] Connection to transport failed. Trying to reconnect...
[Nest] 18 - 04/12/2025, 12:58:29 PM ERROR [Server] AggregateError [ECONNREFUSED]:
at internalConnectMultiple (node:net:1139:18)
at afterConnectMultiple (node:net:1712:7) {
code: 'ECONNREFUSED',
[errors]: [
Error: connect ECONNREFUSED ::1:5672
at createConnectionError (node:net:1675:14)
at afterConnectMultiple (node:net:1705:16) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '::1',
port: 5672
},
Error: connect ECONNREFUSED 127.0.0.1:5672
at createConnectionError (node:net:1675:14)
at afterConnectMultiple (node:net:1705:16) {
errno: -111,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 5672
}
]
}
My .env:
PORT=3001
RABBITMQ_URL=amqp://localhost:15672
RABBITMQ_QUEUE=properties_queue
RABBITMQ_USER=guest
RABBITMQ_PASSWORD=guest
RABBITMQ_QUEUE_DURABLE=false
My docker-compose.yml:
version: '3.8'
services:
properties-ms:
build:
context: .
dockerfile: Dockerfile
container_name: properties-ms
ports:
- "${PORT}:${PORT}" # Mapea el puerto definido en el .env
environment:
- PORT=${PORT}
- RABBITMQ_URL=${RABBITMQ_URL}
- RABBITMQ_QUEUE=${RABBITMQ_QUEUE}
- RABBITMQ_USER=${RABBITMQ_USER}
- RABBITMQ_PASSWORD=${RABBITMQ_PASSWORD}
- RABBITMQ_QUEUE_DURABLE=${RABBITMQ_QUEUE_DURABLE}
networks:
- servers_default # Cambia a la red correcta
networks:
servers_default: # Define la red como externa
external: true
Have somebody idea what kind of error may be causing this?
I run the app using Makefile:
COMPOSE_FILE = docker-compose.yml
build:
@echo "Building the properties-ms container..."
docker compose -f $(COMPOSE_FILE) build
run:
@echo "Running the properties-ms container..."
docker compose -f $(COMPOSE_FILE) up -d properties-ms
clean: stop
@echo "Cleaning volumes, containers, and networks..."
docker compose -f $(COMPOSE_FILE) down -v --rmi all
stop:
@echo "Stopping the properties-ms container..."
docker compose -f $(COMPOSE_FILE) down
restart: stop run
logs:
@echo "Showing logs for the properties-ms container..."
docker logs -f properties-ms
status:
@echo "Checking container status..."
docker ps
Dockerfile:
# Usa una imagen base estable de Node.js
FROM node:lts-alpine
# Establece el directorio de trabajo dentro del contenedor
WORKDIR /app
# Copia los archivos necesarios para instalar dependencias
COPY package*.json ./
COPY tsconfig*.json ./
# Instala todas las dependencias (producción y desarrollo)
RUN npm ci
# Copia el resto de los archivos del proyecto
COPY . .
# Compila el proyecto TypeScript
RUN npm run build
# Elimina las dependencias de desarrollo para reducir el tamaño de la imagen
RUN npm prune --production
# Expone el puerto del gateway
EXPOSE 3000
# Comando para iniciar la aplicación
CMD ["npm", "run", "start:prod"]
RABBITMQ_URL=amqp://localhost:15672; here replacelocalhostwith the proper hostname (the service name in the docker-compose file), also, use the port of5672; you've specified the dashboard port. Additionally, check that the port is published (exposed) and is available. Furthermore, check that the ENV variable is properly read and passed to the RabbitMQ client to initialize.