Making a REST Call to Endpoint in Dockers Making a REST Call to Endpoint in Dockers docker docker

Making a REST Call to Endpoint in Dockers


You need to publish the port (not EXPOSE it). Exposing a port is largely used for links and service contexts. In your example of just running a Docker container, you need to simply publish the port so it is available from the host. You do this with --publish or -p:

docker run -d --name myapp -p 8080:8080 myappimage

Then you can access the application at port 8080 on the host IP address (Docker on Windows and Docker on Mac run a proxy that should allow localhost:8080 to work).


If your application is running inside of a Docker Container and you can access from inside this container using localhost:8080, then all you have to do is add the EXPOSE instruction in your DOCKERFILE (see Dockerfile expose option).

EXPOSE 8080

Then you probably will be able to access from the host machine (where Docker is installed and running) using the default IP from the docker0 network interface. Generally this IP is 172.17.0.X, where X is 2 for your first container, and so on (see docker default networking).

So try to access from outside of the docker using "http://172.17.0.2:8080/endpoint?params..". Also, if you want to allow external access (or access using localhost from the host machine) you should start your container mapping the port from the EXPOSE instruction by using -p parameter (see Mapping Exposed Incoming Ports).