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 http://172.26.0.3:8080

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).

Exception

java.lang.IllegalArgumentException: The character [] is never valid in a domain name.
org.apache.tomcat.util.http.parser.HttpParser$DomainParseState.next(HttpParser.java:1029)
org.apache.tomcat.util.http.parser.HttpParser.readHostDomainName(HttpParser.java:912)
org.apache.tomcat.util.http.parser.Host.parse(Host.java:71)
org.apache.tomcat.util.http.parser.Host.parse(Host.java:45)
org.apache.coyote.AbstractProcessor.parseHost(AbstractProcessor.java:298)
org.apache.coyote.http11.Http11Processor.prepareRequest(Http11Processor.java:793)
org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:375)
org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:891)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1784)
org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191)
org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.base/java.lang.Thread.run(Unknown 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)

root@a1c01f1ae4a8:/usr/local/apache2#

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.