Docker containers - connection refused

0

I have a task running 3 containers (for testing purposes). I have left the network as default, they are all in the same task definition. 2 of them are gunicorn servers running on ports 5000 and 80, respectively. The third needs to communicate with those 2.

I have been searching and trying for hours, but I keep getting "connection refused" when trying to communicate from the third docker to any of the other 2.

Details:

  • They are all in the same task definition.
  • Ports 80, 5000 are exposed with the correct mapping in the task definition
  • Network mode was left as default (also tried bridge)
  • The configuration works fine on my local machine with a bridge network

Is there anything I am missing?

asked a year ago2560 views
1 Answer
0

When running multiple containers, you can use the container's name as the hostname to communicate between the containers.

However, make sure the following:

  • Ensure that your containers have unique names in the task definition. You can use these names as hostnames for inter-container communication.
  • Use container name as the hostname: When trying to connect to another container within the same task definition, use <container_name>:<port> as the target address. For example, if you want to connect to the container running on port 5000, use <container_name>:5000.
  • Ensure that your gunicorn servers are binding to 0.0.0.0 instead of 127.0.0.1. Binding to 0.0.0.0 allows connections from all network interfaces, while binding to 127.0.0.1 only allows connections from the same container. You can bind to 0.0.0.0 using the following command:
gunicorn -w 4 -b 0.0.0.0:5000 app:app
  • If your containers are running in an Amazon ECS environment, verify that the security groups associated with your task allow incoming traffic on ports 80 and 5000.

  • Check the logs of your gunicorn servers and the third container to identify any configuration issues or error messages that could indicate the cause of the connection problem.

profile picture
EXPERT
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions