Getting "failed to resolve broker hostname" when trying to connect to rabbitmq in another docker container

2.4k views Asked by At

I've been searching for hours as to how to connected to an external docker container running RabbitMQ.

I'm trying to run a few services using Nameko which requires RabbitMQ. I've started my RabbitMQ container using the following command:

docker run -d -p 15672:15672 -p 5672:5672 --hostname my-rabbit --name rabbit-container rabbitmq:3-management

I've created a yaml config file called config.yaml with this inside:

AMQP_URI: 'pyamqp://guest:guest@my-rabbit:5672'

I start my rabbit container and my Nameko container and run the following command in the Nameko container's CLI:

nameko shell --config config.yaml

I get a the following error:

OSError: failed to resolve broker hostname

Docker, RabbitMQ, and Nameko are all new technologies to me, so I'm not sure what I'm doing wrong. Please let me know if you see anything that sticks out.

1

There are 1 answers

0
Vinicius Imai On

I start my rabbit with docker-compose:

version: "3"
services:
  rabbit:
    container_name: rabbitmq
    image: rabbitmq:3.7-management
    ports:
        - "5672:5672"
        - "15672:15672" # Exposing RabbitMQ web management on different port for convenience
    restart: always

and config.yaml:

AMQP_URI: amqp://guest:guest@$localhost:5672/