Search code examples
dockerdockerfiledocker-for-windowsdocker-java

Not able to access web app running inside docker container from local machine


I am using windows 10 enterprise version and i have tested docker hello world web app it works just fine.

Dockerfile

FROM adoptopenjdk/openjdk11:latest
WORKDIR /app
COPY ./ ./
EXPOSE 3000

CMD ["java", "-jar", "app.jar"]

These are the steps i followed:

  1. cd to directory where docker file is kept
  2. docker build .
  3. docker run -d -p 3000:3000 imageid

Now inside container i am able to access the app using curl command on port 3000 But from my local machine when i do http://localhost:3000 it says page is not working. Any help is appreciated ?


Solution

  • After further debugging i found my server was only bound to localhost i.e. server connector was only listening on localhost and that's why it worked inside only container. I bound internal network interface(which resolved to an ip) to my server along with localhost(this is happening during server start-up), after this i was able to access the app from outside the container.