0

I have a service running on my local machine on port 8500 - bound to 127.0.0.1:8500.

The machine is running Docker Engine - Community 20.10.20 on Ubuntu Linux 22.04.

On the local machine, I get the correct response if I do:

curl 127.0.0.1:8500
>> <a href="/ui/">Moved Permanently</a>.

I want to be able to forward this service to a Docker container running on the same machine, such that 127.0.0.1:8500 within the container produces the same result as above. The Docker container is provisioned using docker compose. I'm not able to use network_mode='host' in this situation.

If I add to the docker-compose.yml file for the container:

ports:
 - "172.17.0.1:8500:8500"

and run curl in the container, I get the following error:

curl: (7) Failed to connect to 127.0.0.1 port 8500: Connection refused

What am I doing wrong?

user1022788
  • 419
  • 8
  • 18
  • You need to set the process to bind to 0.0.0.0 or else it will be unreachable from outside its own container; see for example [Docker app server ip address 127.0.0.1 difference of 0.0.0.0 ip](https://stackoverflow.com/questions/59179831/docker-app-server-ip-address-127-0-0-1-difference-of-0-0-0-0-ip). The IP address part of `ports:` is optional, and if you set that to _only_ `172.17.0.1` then the process won't be reachable from `127.0.0.1` on the host, that's a different network interface. – David Maze Oct 26 '22 at 13:51

0 Answers0