4

I am wondering if is it possible to connect to an app on local host from Docker container.

I run two Docker container which are connected to each other via link option. But how can I connect one of the containers to the local host?

rset_d
  • 109
  • 1
  • 1
  • 5

2 Answers2

2

Yes, use docker run --network=container:<container-id>

--network='container:': reuse another container's network stack

This let you run a container sharing the same network interface (then localhost) from another container.


Alternatively, you can use the host mode to give your containers the same network ips that the host has (including localhost). docker run --network=host:

--network= 'host': use the Docker host network stack

Docs: https://docs.docker.com/engine/reference/run/#name-name

Robert
  • 33,429
  • 8
  • 90
  • 94
0

I think it is possible. Try communicate with the host's<ip:port>

ip: useip addror something similar to get the one of eth0,not the one of docker0

port:the one you assigned to the app

To make the process easier,perhaps turn selinux and firewall down when you try.

Philip.Z
  • 43
  • 7