Docker Community Forums

Share and learn in the Docker community.

How to access a website running in a container when you´re using network_mode: host

I have a very tricky topic because I need to access a private DB in AWS. In order to connect to this DB, first I need to create a bridge like this:


Via I can connect to the DB in my Java app. Let´s say the port is 9991 for this case.

My docker files more or less look this:


version: '3.4'
    image: fanmixco/example:v0.01
      context: .
    network_mode: host
      - SPRING_DATASOURCE_URL=jdbc:postgresql://host.docker.internal:9991/MY_DB


FROM openjdk:11
RUN mkdir /home/app/
WORKDIR /home/app/
RUN mkdir logs
COPY ./target/MY_JAVA_APP.jar .


ENTRYPOINT ["java", "-jar", "MY_JAVA_APP.jar"]

The image runs properly. However, if I try:

  • using localhost:8080/MY_APP fails
  • using fails
  • getting the container’s IP and use it later fails
  • using host.docker.internal/MY_APP fails

I´m wondering how I can test my app. I know it´s running because I get a successful message in the console and the new data was added to the DB, but I don´t know how I can test it or access it. Any idea of the proper way to do it? Thanks.


  1. I´m running my Images in Docker Desktop for Windows.

  2. I have another case using tomcat 9 and running CMD ["", "run"] and I know it’s working because I get this message in the console:

INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [9905] milliseconds

But I cannot access it again.

Use --network=“host” in your docker run command, then 127.0. 0.1 in your docker container will point to your docker host. Note: This mode only works on Docker for Linux, per the documentation.

Hi Lewish, it works in Windows because I can add data to the AWS DB but I cannot access the website in any way.