Docker微服务映像无法连接到本地MySQL服务器
这就是我在application.properties文件中配置MySQL的方式Docker微服务映像无法连接到本地MySQL服务器,mysql,docker,microservices,Mysql,Docker,Microservices,这就是我在application.properties文件中配置MySQL的方式 spring.datasource.url=jdbc:mysql://127.0.0.1:3306/roaming spring.datasource.username=root spring.datasource.password=root #spring.datasource.initialization mode=始终 spring.jpa.show sql=true spring.jpa.hibernat
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/roaming
spring.datasource.username=root
spring.datasource.password=root
#spring.datasource.initialization mode=始终
spring.jpa.show sql=true
spring.jpa.hibernate.ddl auto=validate
spring.jpa.properties.hibernate.dialogue=org.hibernate.dialogue.mysql5dialogue
如果要从容器连接到主机,必须使用--network host
选项运行容器。更多。容器中:
127.0.0.1
是本地集装箱的平均值。如果您想连接主机中的MySQL服务器。(容器外部,但与容器相同的主机)
应配置:
spring.datasource.url=jdbc:mysql://127.0.0.1:3306/roaming
改为:
spring.datasource.url=jdbc:mysql://172.17.0.1:3306/roaming
172.17.0.1
是容器网络的默认ip网关。在spring.datasource.url中使用host.docker.internal而不是localhost。您是如何配置code中的连接localhost string
的?spring.datasource.url=jdbc:mysql://127.0.0.1:3306/roaming spring.datasource.username=root-spring.datasource.password=root#spring.datasource.initialization mode=always spring.jpa.show sql=true spring.jpa.hibernate.ddl auto=validate spring.jpa.properties.hibernate.dialen=org.hibernate.dialen.mysql5dialen这是我在application.properties文件@thanhngyuenvany中配置的方式。您需要使用Docker networkingue创建Docker容器间通信此链接是在不同容器中运行的数据库,还是在同一主机上Docker外部运行的数据库?