title: consumer: Cannot connect to amqp://user:**@rabbit1:5672//: failed to resolve broker hostname
body: <p>I have perused through very similar stackoverflow questions and changed my code to what it is now. I am still getting the <code>cannot resolve broker hostname</code> error. If I just use <code>amqp:user:mypass@locahost:5672</code> I get the a <code>connection refused</code></p>
  
  <pre><code># docker-compoose.yml
  version: "3.8"
  
  services: 
    broker:
      image: rabbitmq:3-management-alpine
      hostname: rabbit1
      environment: &amp;env
        RABBITMQ_ERLANG_COOKIE: "SWQOKODSQALRPCLNMEQG"
        RABBITMQ_DEFAULT_USER: "user"
        RABBITMQ_DEFAULT_PASS: "password"
        RABBITMQ_DEFAULT_VHOST: "/"
        CELERY_BROKER_URL: "amqp://user:password@rabbit1:5672"
      ports:
        - "5672:5672"
        - "15672:15672"
      expose:
        - "5672"
      networks:
        - webnet
      volumes: 
        - .:/home/user
  
    worker:
      build: 
        context: .
        dockerfile: ./worker/Dockerfile
      command: ["celery", "worker", "--app=worker.tasks.app", "--loglevel=INFO"]
      environment: 
        &lt;&lt;: *env
      links: 
        - broker 
      depends_on: 
        - broker
      networks:
        - webnet
      volumes: 
        - .:/home/user
  
  
  networks:
      webnet:
  </code></pre>
  
  <pre><code># Dockerfile
  FROM python:3.7-slim
  
  RUN groupadd user &amp;&amp; useradd --create-home --home-dir /home/user -g user user
  ENV CELERY_USER = user
  
  WORKDIR /home/user
  COPY . .
  
  RUN pip install --no-cache-dir -r requirements.txt
  RUN rm requirements.txt
  </code></pre>
  
  <p>I have tried just starting the rabbitmq broker through docker-compose and then manually doing a <code>celery worker --app=tasks.app</code> and that will work after setting the <code>CELERY_BROKER_URL=amqp://user:mypass@localhost:5672</code></p>
  
  <p>It throws the error when I have the worker and broker in the same yaml. I've tried it without the network, manually setting the CELERY_BROKER_URL in the Dockerfile also. If anyone has ideas what I'm doing wrong, I would really appreciate it. </p>