I'm trying to receive data sent from a node.js application to a flask application, both running inside their own docker containers, networked using docker-compose.
Here is my flask application:
from flask import Flask, request
import json
# Server connection information
host = "" # Might need to make this empty when service is dockerized.
port = 65432
# Set up flask server
app = Flask(__name__)
@app.route('/inbound_message', methods=['POST'])
def inbound_message():
data = request.get_json()
received_message = data['message']
print(received_message)
welcome_message = "Hi, thanks for getting in touch! I'm currently a work in progress - please check back soon!"
response_message = welcome_message
return json.dumps({"response_message": response_message})
if __name__ == "__main__":
app.run(port=port)
Here is the function being called in my node application:
async function inboundMessage(message) {
const data = {
message: message
};
const options = {
method: 'POST',
uri: 'http://ai-core:65432/inbound_message',
body: data,
json: true
};
return await request(options)
.then(function (parsedBody) {
return parsedBody['response_message'];
})
.catch(function (err) {
console.log(err)
});
}
And my docker-compose.yml file:
version: '3'
services:
ai-webserver:
container_name: ai-webserver
build:
context: './web_server'
ports:
- '8080:8080'
networks:
- ai-services
links:
- 'ai-core:ai-core'
ai-core:
container_name: ai-core
build:
context: './core'
ports:
- '65432:65432'
networks:
- ai-services
networks:
ai-services:
driver: bridge
ipam:
driver: default
The error I'm getting from the node application is 'RequestError: Error: connect ECONNREFUSED 172.23.0.3:65432'. I'm unsure why this isn't working, as it works fine when the applications aren't running inside a container, which suggests its just an issue with the networking of the containers. I tried moving from individual containers over to docker-compose with a docker network, but I'm unsure if I've done this correctly. I've tried a few different uri's in the node.js function without any success.
Any help with this would be much appreciated!