I have installed MariaDB on Ubuntu (not as a Docker image). Then I have an image with a Spring Boot Application. This Spring Boot application should be reachable on port 8002 and be able to connect to MariaDB on the host system.
If I start docker run without --network=host, the Spring Boot application in the docker image cannot connect to the database.
If I use the --network=host parameter, the Spring Boot application can connect to the database, but the application is not reachable on port 8002.
docker run \
   -e "DB_URL=jdbc:mariadb://127.0.0.1:3306/app" \
   -e "DB_USERNAME=***" \
   -e "DB_PASSWORD=***" \
   -it \
   -p 8002:8080 \
   --network=host \
   repository/app:0.0.3
CONTAINER ID   IMAGE                   COMMAND            CREATED         STATUS          PORTS       NAMES
2fe96a608298   repository/app:0.0.3    "java -jar app…"   2 minutes ago   Up 2 minutes                hardcore_hopper
I have tried many. But I can't get the application to be reachable on a port.
 
    