title: pika.exceptions.AMQPConnectionError in Django with Docker
body: <p>I'm using docker to run two django services. RabbitMq is installed in the host not in a container. When I run the django development server without the container rabbitmq connection works. But when I use the docker-compose up it gives <strong>pika.exceptions.AMQPConnectionError</strong> error. I restarted the rabbitmq but it doesn't resolve the problem</p>
  <p><strong>Dockerfile</strong></p>
  <pre><code>FROM python:3.9
  ENV PYTHONUNBUFFERED 1
  WORKDIR /app
  COPY requirements.txt /app/requirements.txt
  RUN pip install -r requirements.txt
  COPY . /app
  
  CMD python manage.py runserver 0.0.0.0:8000
  
  </code></pre>
  <p><strong>Dockercompose.yml</strong></p>
  <pre><code>version: '3.3'
  services:
    blog_writer:
      build:
        context: .
        dockerfile: DockerFile
      ports:
        - 8001:8000
      volumes:
        - .:/app
  
  </code></pre>
  <p><strong>Producer.py</strong></p>
  <pre><code>import json
  import pika
  
  connection = pika.BlockingConnection(pika.ConnectionParameters('localhost', heartbeat=600, blocked_connection_timeout=300))
  channel = connection.channel()
  
  def publish(method, body):
      properties = pika.BasicProperties(method)
      channel.basic_publish(exchange='', routing_key='blogs', body=json.dumps(body), properties=properties)
  
  </code></pre>
  <p><strong>RabbitMq Status</strong></p>
  <pre><code>sudo systemctl status rabbitmq-server.service 
  [sudo] password for navanjane: 
  ● rabbitmq-server.service - RabbitMQ broker
       Loaded: loaded (/lib/systemd/system/rabbitmq-server.service; enabled; vend&gt;
       Active: active (running) since Sat 2022-01-15 18:51:40 +0530; 1 day 5h ago
     Main PID: 1105 (beam.smp)
        Tasks: 28 (limit: 9342)
       Memory: 105.7M
       CGroup: /system.slice/rabbitmq-server.service
               ├─1105 /usr/lib/erlang/erts-12.1.5/bin/beam.smp -W w -MBas ageffcb&gt;
               ├─1170 erl_child_setup 32768
               ├─1556 /usr/lib/erlang/erts-12.1.5/bin/epmd -daemon
               ├─1588 inet_gethost 4
               └─1589 inet_gethost 4
  
  ජන 15 18:51:35 navanjane-Ubuntu rabbitmq-server[1105]:   Doc guides:  https://r&gt;
  ජන 15 18:51:35 navanjane-Ubuntu rabbitmq-server[1105]:   Support:     https://r&gt;
  ජන 15 18:51:35 navanjane-Ubuntu rabbitmq-server[1105]:   Tutorials:   https://r&gt;
  ජන 15 18:51:35 navanjane-Ubuntu rabbitmq-server[1105]:   Monitoring:  https://r&gt;
  ජන 15 18:51:35 navanjane-Ubuntu rabbitmq-server[1105]:   Logs: /var/log/rabbitm&gt;
  ජන 15 18:51:35 navanjane-Ubuntu rabbitmq-server[1105]:         /var/log/rabbitm&gt;
  ජන 15 18:51:35 navanjane-Ubuntu rabbitmq-server[1105]:         &lt;stdout&gt;
  ජන 15 18:51:35 navanjane-Ubuntu rabbitmq-server[1105]:   Config file(s): (none)
  ජන 15 18:51:40 navanjane-Ubuntu rabbitmq-server[1105]:   Starting broker... com&gt;
  ජන 15 18:51:40 navanjane-Ubuntu systemd[1]: Started RabbitMQ broker.
  
  </code></pre>