1

I am invoking REST API using curl for my application running within container.I am unable to access the REST API using curl & getting below message

root@2p1aa752bf12f:/# curl 'http://127.0.0.1' -x $http_proxy
curl: (7) Failed to connect to 127.0.0.1 port 80: Connection refused

I tried multiple ways from within the container but it is not working:

  1. With IPaddress
  2. with localhost

However when i do ping test i am able to get the response

root@2p1aa752bf12f:/# ping localhost
localhost (127.0.0.1) 56(84) bytes of data.
64 bytes from localhost (127.0.0.1): icmp_seq=1 ttl=64 time=0.033 ms
64 bytes from localhost (127.0.0.1): icmp_seq=2 ttl=64 time=0.015 ms
64 bytes from localhost (127.0.0.1): icmp_seq=3 ttl=64 time=0.031 ms

Also i would want to invoke REST API running on a different container as well.My containers are connected using Bridge network I can ping it but cannot access REST API using curl.I do not get any response & it hangs

Expecting to invoke REST API from within container & also access REST API exposed in another container

anne2233
  • 11
  • 1
  • You are testing port 80, but your comment suggests you are running your server on port 8080. – Evert Mar 31 '23 at 16:23

1 Answers1

0

Consider that ping and curl do different things.

You'll use ping command for test IP address, hostname reachability

ping localhost # domain name translated into 127.0.0.1 in your system

In your case curl http://127.0.0.1 did something more:

  • trying to reach localhost
  • trying to establish connection with the 80 port (standard http port)

Your 'localhost' (your container) did not provide any connection to your curl request avoiding connectivity.

Ensure you have a web server up and running on that http:<HOST>:<PORT>


references:

  • similar question -> here
  • docker web tutorial -> here
  • curl -> linux man page here
  • ping -> official curl man page here
bigmauri
  • 69
  • 9