Connection refused on container to container communication in same container network

Hello Community.

While i was trying to curl to another container which has the same network it was not able to connect i was getting the below error

Error:-curl: (7) Failed to connect to product-2_frontend-2_1 port 6060: Connection refused

i guess it was not able to access the container port.

can u please help me on this how to resolve this.

When you are inside a container, and want to communicate with another container in the same container network, you need to use the container port, not the published host port.

curl http://product-2_frontend-2_1:8080

Note: please do not post screenshot of text - next time please paste it as test and wrap it in a “</> Preformated text” block (if not visible, it is in the submenu of the gear icon).

Thanks for the reply Metin Y

But i was able to get a response with curl

When i try to give curl http://product-2_frontend-2_1:8080 i was getting this error

curl http://product-2_frontend-2_1:8080
<!doctype html>HTTP Status 400 – Bad Requestbody {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;} h1 {font-size:22px;} h2 {font-size:16px;} h3 {font-size:14px;} p {font-size:12px;} a {color:black;} .line {height:1px;background-color:#525D76;border:none;}

HTTP Status 400 – Bad Request

Type Exception Report

Message The character [] is never valid in a domain name.

Description The server cannot or will not process the request due to something that is perceived to be a client error (e.g., malformed request syntax, invalid request message framing, or deceptive request routing).


java.lang.IllegalArgumentException: The character [] is never valid in a domain name.
java.base/ Source)

Note The full stack trace of the root cause is available in the server logs.

Apache Tomcat (TomEE)/9.0.71 (8.0.14)


Ah, I see. Well that’s because underscores are not allowed for domain names.

Please use the service name instead of the container name. As you didn’t share your compose file, I am not going to assume anything.