0

I have a docker container running on my local machine(mac). I have another program which listens on localhost. How do I make code running in docker container to connect to this process?

Sandy
  • 2,253
  • 6
  • 24
  • 33

1 Answers1

0

You can do this through the port flag when running Docker.

docker run -it -p 8080:8080 myimage

-p 8080:8080 is the flag. The right hand side of the : is port that your docker container is listening to. The left hand side is where you want that to be mapped to on the local host. In this example, when I access localhost:8080, I am accessing what the Docker container is listening to on that port.

Zac R.
  • 156
  • 1
  • 3
  • I think you got me wrong. I don't want to connect to docker container, but process within docker container should be able to connect to process running locally on my machine. So from docker container running code should be able to connect to process running on localhost. – Sandy Apr 25 '17 at 10:53
  • I see. Is this the sort of problem your facing? http://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach – Zac R. Apr 25 '17 at 11:00
  • Eventually this answer looks like what you may need: http://stackoverflow.com/a/31328031/3017509 – barat Apr 25 '17 at 11:01
  • @barat I think that thread points to the same problem. I will try solutions there. thanks – Sandy Apr 25 '17 at 12:51