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?

已提问 1 年前2600 查看次数
1 回答
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
专家
已回答 1 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则