0

On my localhost I have a Django application running on port 8000. A Docker compose sets up different containers, among them a Flask application with the config:

redirection-service:
  container_name: redirection-service
  build: 
    context: "..."
  ports:
    - 5000:5000
  links:
    - redis

In the flask application I use a requests call to access an endpoint of the Django application on the localhost:

 backend_url = 'localhost:8000/...'
 requests.post(backend_url, data={}, allow_redirects=True, verify=False)

But I get the error

 requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8000): Max retries exceeded with url: /.../ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f4d706f7588>: Failed to establish a new connection: [Errno 111] Connection refused',))
davidism
  • 121,510
  • 29
  • 395
  • 339
wasp256
  • 5,943
  • 12
  • 72
  • 119
  • When you connect to `localhost:8000` it's the same container network namespace. Are both processes running in the same container? – David Maze Nov 26 '18 at 13:31
  • As stated above, Django is running on the localhost and Flask inside a container – wasp256 Nov 26 '18 at 13:42
  • Django is running in localhost, and Flask is running in localhost, and they're different localhosts. – David Maze Nov 26 '18 at 13:43
  • okay so how do I `request.post` from inside the container to the django app on the actual local host? – wasp256 Nov 26 '18 at 13:46

1 Answers1

0

You need to have in mind that different containers have different addresses. So localhost:8000 on flask has NO IDEA of the django running on the other container. You need to use django's internal ip address or resolve the host name in another way

Walucas
  • 2,549
  • 1
  • 21
  • 44