I have 4 Node JS microservices running simultaneously on ec2 instance with docker, all of them running on different ports, if I try to access the server that is running or port 4000 locally (through terminal) using curl like this:
curl -X POST -d '{"type":"2fa","data":{"email":"example@gmail.com","otp":"700558","username":"example"}}' -H "Content-Type: application/json" http://localhost:4000/send-mail
it gives a response, and also if i use postman and send the request through server IP and port, it works and it gives response, only when another microservice trying to access the same microservice I am talking about locally on the server, it shows : net::ERR_CONNECTION_REFUSED for the port 4000, as if it's turned off or it cannot find it.
this is the output of docker-compose ps:
Name Command State Ports
----------------------------------------------------------------------------------------------------------------------
microservice_be-admin_1 docker-entrypoint.sh node ... Up 0.0.0.0:3001->3001/tcp,:::3001->3001/tcp
microservice_be-auth_1 docker-entrypoint.sh node ... Up 0.0.0.0:3000->3000/tcp,:::3000->3000/tcp
microservice_be-helper_1 docker-entrypoint.sh node ... Up 0.0.0.0:4000->4000/tcp,:::4000->4000/tcp
microservice_be-user_1 docker-entrypoint.sh node ... Up 4000/tcp, 0.0.0.0:5000->5000/tcp,:::5000->5000/tcp
I checked all the .env files and they are working fine on the same ports, i also tried the same process locally and it works, just on the server its not working
Oh, ok, That make sense, I will try to change that, thank you.
Thank you, this solved my problem