user16655
user16655

Reputation: 1941

How to make request to server running on docker

On my machine I'm running an application in Docker (it runs on http://localhost:8181).

I've started Docker with docker run -p 8181:8181 myapp.

After some searching I've tried to send my request to the output of docker0 when I run ifconfig, which is 172.17.0.1, and the ip of my computer. I've also tried localhost and 0.0.0.0: http://<ip>:8181/myapp. I'm running Ubuntu 16.04.

How can i send a request to the server running in docker?

Upvotes: 2

Views: 883

Answers (1)

BMitch
BMitch

Reputation: 263509

Change your application from listening on localhost:8181 to listening on 0.0.0.0:8181. Docker port mapping will route to the IP of the container, not the loopback interface inside the container, so your app needs to listen on all interfaces.

Then you run your container as you have with the port mapping option that maps 8181 on the host to the same port inside the container:

docker run -p 8181:8181 myapp

Lastly, you connect to the IP of your docker host on port 8181 to access the application. With newer versions of Docker for Win/Mac, and all versions of the Linux install, this can be localhost:8181 on your host. If you are using docker-machine (with docker-toolbox), that IP needs to be your remote docker host or VM, that IP will be listed in docker-machine ls.

Upvotes: 3

Related Questions