I have two docker containers on the same network. I want to send some data with POST and GET methods over HTTP. I am doing:
app = Flask(__name__)
is_processing = False # Flag to indicate whether processing is ongoing
receiver_url = "http://172.18.0.2:8889/receive_data" # Define the receiver URL
and
app.run(port=8889)
on the sender container I am doing:
def send_data_to_receiver(data):
receiver_url = "http://172.18.0.2:8889/receive_data"
data_serializable = [x.tolist() for x in data]
response = requests.post(receiver_url, json=data_serializable)
if response.status_code == 200:
print("Data sent successfully to receiver notebook")
else:
print("Failed to send data to receiver notebook")
The above works successfully between jupyter notebooks, however when I am trying to add them in docker containers I get the following error:
File "/usr/local/lib/python3.11/dist-packages/requests/adapters.py", line 519, in send
raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPConnectionPool(host='172.18.0.2', port=8889): Max retries exceeded with url: /receive_data (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7fc750529cd0>: Failed to establish a new connection: [Errno 111] Connection refused'))
What is wrong with my setup?