0

I have a docker container that is running a node.js application. From the system the container is running on I can do things like ...

curl http://<IP address of my docker container>/users ....

... and they the expected json response. Now I have installed an apache web server on my system I have some angular.js where I am attempting to communicate to the REST API on the docker container. But the docker container, of course, is not accessible from the rest of the hosts on my network. Is there an easy way to set up some sort of proxy? I am kinda of familiar with HAProxy. Could I set up HAProxy somehow?

UPDATE:

I start my docker container like so:

[red@vm-red ~]$ sudo docker run -p 3000:8080 -t -i redsimage
...

From the command line on host vm-red I can execute this curl ...

[red@vm-red ~]$ curl -H "Content-Type: application/json" http://172.17.0.6:3000/user

... and get the expected results. But if I use something like 'postman' from my laptop or my browsers on my laptop and point them to http://vm-red:8080/user I get nothing. What am I doing wrong?

1

You can easily map a port in you docker container to host machines port. For example say your host machines ip is 10.20.30.40, you can make your api in docker machine available in that ip by mapping the api's port to port 80 of the host machine. Now if you are already have something hosted in the host machine, then you can map it to some other port, say 8080.

By mapping the docker images port to port 80 on the host, your api will be accessible at 10.20.30.40/user, but if you map it to a different port like 8080, your api will be accessible at 10.20.30.40:8080/users

This can be done using the simple command below:

# Maps the container port to a random host port.
docker run -d -P yourImage 

# Maps the host port of 8080 to the container port 80
docker run -d -p "8080:80" yourImage 

you could read more about it here.

  • I think you meant to write docker run -d -p 8080:80 yourImage right? – Red Cricket Oct 28 '15 at 4:59
  • Hmmm ... that doesn't seem to help. I updated my question. – Red Cricket Oct 28 '15 at 5:17
  • Ah ... this does the trick. sudo docker run -p 7777:3000 -t -i redsimage – Red Cricket Oct 28 '15 at 6:02
  • Glad it worked. :) If its solved, you can mark the answer as accepted. @RedCricket – Safwan Erooth Oct 28 '15 at 6:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.