Vladimir
Vladimir

Reputation: 11

socket.gaierror: [Errno -2] Name or service not known docker-compose + rabbitmq + pika (Python)

I have docker container with rabbitmq, it has an address: 192.168.220.10, domain in my local etc/hosts: rabbitmq

So, Im trying to use pika (python) from another container with fastapi app, it has an address: 192.168.220.5.

Of course, all containers have a network: net: driver: bridge ipam: config: - subnet: 192.168.220.0/24

Below rabbitmq container code from docker-compose.yml

rabbitmq:
  container_name: rabbitmq
  image: rabbitmq:3-management-alpine
  restart: always
  ports:
    - "5672:5672"
    - "15672:15672"
  environment:
    RABBITMQ_DEFAULT_USER: rabbitmq
    RABBITMQ_DEFAULT_PASS: 27474129
  networks:
    net:
      ipv4_address: 192.168.220.10

So theres a problem at the bottom

credentials = pika.PlainCredentials('rabbitmq', '27474129')
conn_params = pika.ConnectionParameters(host="http://rabbitmq", port=5672)
connection = pika.BlockingConnection(conn_params)
channel = connection.channel()

Im getting an error: socket.gaierror: [Errno -2] Name or service not known

I`ve tried:
Use ports: 15672 and 5672.
Use host: "http://192.168.220.10

Upvotes: 1

Views: 626

Answers (1)

Vladimir
Vladimir

Reputation: 11

parameters = pika.URLParameters('amqp://rabbitmq:27474129@rabbitmq:5672/%2F')
connection = pika.BlockingConnection(parameters)

Upvotes: 0

Related Questions