Connect docker container to local MySQL DB workbench

HI I have my web application running on my local machine and connected to mysql workbench, now I'm trying to connect to webapp. I can’t get him to connect to the database on my local machine (I run docker for windows), can anyone tell me how I will do this. Here is what I still have.

`docker run -it -e "CATALINA_OPTS=-Dspring.profiles.active=dev -DPARAM1=DEV" -p 8080:8080 -p 8005:8005 -p 8009:8009 -p 3306:3306 --add-host=docker:192.168.1.7 -v C:\myapp\trunk\target\myapp.war:/usr/local/tomcat/webapps/myapp.war --name waitapp tomcat:8.0.38-jre8`

after a few seconds, I started docker ps -a

CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS                           PORTS                                                                                            NAMES
2a1764dd9640        tomcat:8.0.38-jre8     "catalina.sh run"        2 minutes ago       Up 2 minutes                     0.0.0.0:3306->3306/tcp, 0.0.0.0:8005->8005/tcp, 0.0.0.0:8009->8009/tcp, 0.0.0.0:8080->8080/tcp   waitapp

The container works, but I get 404 Not found when I try to execute a break request, this is the same as when starting from the spring toolbox using the built-in tomcat server.

Note I do not want to start a separate mysql container and bind the two over the network, I just want to try to get a new docker application to connect to my local MySQL DB.

+4
source share
1 answer

As mentioned in this post , you can try 2 things:

  • Add a gateway and use it from containers, for example

docker network create -d bridge --subnet 192.168.0.0/24 --gateway 192.168.0.1 dockernet

  1. In addition to the application container, run a proxy server (ngnix?), Which will route calls to the database if necessary

This answer also shows how you can get the host IP address inside the docker container.

0

Source: https://habr.com/ru/post/1663860/


All Articles