title: Docker and Scrapyrt - ConnectionRefusedError: [Errno 111]
body: <p>I need to open a background listener for Scrapy on my 'web' service in a Docker application, like so:</p>
  
  <p><strong>task</strong>:</p>
  
  <pre><code>@celery.task(
  queue='scraping')
  def scrape():
     params = {
            'spider_name': 'spider',
            'start_requests':True
              }
     response = requests.get('http://localhost:9080/crawl.json', params)
     return {'Status': 'Scraping completed!',
             'features': response}
  </code></pre>
  
  <p>My application runs a nginx reverse proxy server, and services are configured like so: </p>
  
  <p><strong>docker-compose.yml:</strong></p>
  
  <pre><code>services:
  
    web:
      build:
        context: ./services/web
        dockerfile: Dockerfile-dev
      volumes:
        - './services/web:/usr/src/app'
  
      ports:
        - 5001:5000
      depends_on:  
        - web-db
        - redis
  
    nginx:
      build:
        context: ./services/nginx
        dockerfile: Dockerfile-dev
      restart: always
      ports:
        - 80:80
      depends_on:
        - web
        - client
        - redis
  
   scrapyrt:
      image: vimagick/scrapyd:py3
      command: scrapyrt -i 0.0.0.0 -p 9080
      restart: always
      ports:
        - '9080:9080'
      volumes:
        - ./services/web:/usr/src/app
      working_dir: /usr/src/app/project/api
      depends_on:
        - web
  </code></pre>
  
  <p>Route in 'web' service sends request via scrape function using an async task:</p>
  
  <pre><code>@task_bp.route('/blogs/&lt;user_id&gt;', methods=['GET'])
        task = scrape.apply_async([user_id])
        response_object = {
              'status': 'success',
              'data': {
                  'task_id': task.id,
                  'results': task.get(),
              }
          }
        return jsonify(response_object), 202
  </code></pre>
  
  <p><strong>curl</strong>:</p>
  
  <pre><code>curl -X GET http://localhost:5001/blogs/1 -H "Content-Type: application/json" 
  </code></pre>
  
  <p>Twisted server seems to be working:</p>
  
  <pre><code>scrapyrt_1         | 2019-05-14 02:12:18+0000 [-] Log opened.
  scrapyrt_1         | 2019-05-14 02:12:18+0000 [-] Site starting on 9080
  scrapyrt_1         | 2019-05-14 02:12:18+0000 [-] Starting factory &lt;twisted.web.server.Site object at 0x7fcfdc977b70&gt;
  </code></pre>
  
  <p>but celery log throws me the following error (Full traceback):</p>
  
  <pre><code>Traceback (most recent call last):
    File "/usr/lib/python3.6/site-packages/urllib3/connection.py", line 159, in _new_conn
      (self._dns_host, self.port), self.timeout, **extra_kw)
    File "/usr/lib/python3.6/site-packages/urllib3/util/connection.py", line 80, in create_connection
      raise err
    File "/usr/lib/python3.6/site-packages/urllib3/util/connection.py", line 70, in create_connection
      sock.connect(sa)
  ConnectionRefusedError: [Errno 111] Connection refused
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 600, in urlopen
      chunked=chunked)
    File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 354, in _make_request
      conn.request(method, url, **httplib_request_kw)
    File "/usr/lib/python3.6/http/client.py", line 1239, in request
      self._send_request(method, url, body, headers, encode_chunked)
    File "/usr/lib/python3.6/http/client.py", line 1285, in _send_request
      self.endheaders(body, encode_chunked=encode_chunked)
    File "/usr/lib/python3.6/http/client.py", line 1234, in endheaders
      self._send_output(message_body, encode_chunked=encode_chunked)
    File "/usr/lib/python3.6/http/client.py", line 1026, in _send_output
      self.send(msg)
    File "/usr/lib/python3.6/http/client.py", line 964, in send
      self.connect()
    File "/usr/lib/python3.6/site-packages/urllib3/connection.py", line 181, in connect
      conn = self._new_conn()
    File "/usr/lib/python3.6/site-packages/urllib3/connection.py", line 168, in _new_conn
      self, "Failed to establish a new connection: %s" % e)
  urllib3.exceptions.NewConnectionError: &lt;urllib3.connection.HTTPConnection object at 0x7ff217792a90&gt;: Failed to establish a new connection: [Errno 111] Connection refused
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "/usr/lib/python3.6/site-packages/requests/adapters.py", line 449, in send
      timeout=timeout
    File "/usr/lib/python3.6/site-packages/urllib3/connectionpool.py", line 638, in urlopen
      _stacktrace=sys.exc_info()[2])
    File "/usr/lib/python3.6/site-packages/urllib3/util/retry.py", line 399, in increment
      raise MaxRetryError(_pool, url, error or ResponseError(cause))
  urllib3.exceptions.MaxRetryError: HTTPConnectionPool(host='localhost', port=9080): Max retries exceeded with url: /crawl.json?spider_name=allmusic_smooth_tracks&amp;start_requests=True (Caused by NewConnectionError('&lt;urllib3.connection.HTTPConnection object at 0x7ff217792a90&gt;: Failed to establish a new connection: [Errno 111] Connection refused',))
  
  During handling of the above exception, another exception occurred:
  
  Traceback (most recent call last):
    File "/usr/lib/python3.6/site-packages/celery/app/trace.py", line 382, in trace_task
      R = retval = fun(*args, **kwargs)
    File "/usr/lib/python3.6/site-packages/celery/app/trace.py", line 641, in __protected_call__
      return self.run(*args, **kwargs)
    File "/usr/src/app/brandio/api/routes/background.py", line 904, in scrape_allmusic
      response = requests.get('http://localhost:9080/crawl.json', params)
    File "/usr/lib/python3.6/site-packages/requests/api.py", line 75, in get
      return request('get', url, params=params, **kwargs)
    File "/usr/lib/python3.6/site-packages/requests/api.py", line 60, in request
      return session.request(method=method, url=url, **kwargs)
    File "/usr/lib/python3.6/site-packages/requests/sessions.py", line 533, in request
      resp = self.send(prep, **send_kwargs)
    File "/usr/lib/python3.6/site-packages/requests/sessions.py", line 646, in send
      r = adapter.send(request, **kwargs)
    File "/usr/lib/python3.6/site-packages/requests/adapters.py", line 516, in send
      raise ConnectionError(e, request=request)
  requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=9080): Max retries exceeded with url: /crawl.json?spider_name=allmusic_smooth_tracks&amp;start_requests=True (Caused by NewConnectionError('&lt;urllib3.connection.HTTPConnection object at 0x7ff217792a90&gt;: Failed to establish a new connection: [Errno 111] Connection refused',))
  </code></pre>
  
  <p>what am I missing?</p>