为了账号安全,请及时绑定邮箱和手机立即绑定

Docker容器中的Java服务未连接到主机mysql

Docker容器中的Java服务未连接到主机mysql

回首忆惘然 2021-04-30 14:17:17
我在无法连接到本地托管的mysql的docker容器中运行Java微服务。docker在IP地址为172.0的网络中运行。。。如果我直接以java -jar的身份执行Java服务,则它可以连接到以10.0运行的mysql。。docker-compose文件 version: '2.0'services:  config-server:        image: test/config-server        container_name: config-server        environment:          - GIT_USERNAME=${GIT_USERNAME}          - GIT_PASSWORD=${GIT_PASSWORD}        ports:          - 8889:8889        entrypoint: ["java", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseCGroupMemoryLimitForHeap", "-Dspring.profiles.active=docker", "-Drun.arguments=GIT_USERNAME=${GIT_USERNAME}, GIT_PASSWORD=${GIT_PASSWORD} -Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]  discovery-server:      image: test/discovery-server      container_name: discovery-server      links:        - config-server      depends_on:        - config-server      entrypoint: ["./wait-for-it.sh","config-server:8889","--timeout=60","--","java", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseCGroupMemoryLimitForHeap", "-Dspring.profiles.active=docker", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]      ports:        - 8761:8761  web-authentication:      image: test/web-authentication      container_name: web-authentication      links:        - config-server        - discovery-server      depends_on:        - discovery-server      entrypoint: ["./wait-for-it.sh","discovery-server:8761","--timeout=60","--","java", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseCGroupMemoryLimitForHeap", "-Dspring.profiles.active=docker", "-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]      ports:        - 8444:8444  gateway:      image: test/gateway      container_name: gateway      links:        - config-server        - discovery-server        - web-authentication      depends_on:        - discovery-server
查看完整描述

1 回答

?
FFIVE

TA贡献1797条经验 获得超6个赞

在docker-compose.yml中配置网络配置后,此问题已解决,该问题是mysql和Docker容器在不同的子网中运行。


查看完整回答
反对 回复 2021-05-12
  • 1 回答
  • 0 关注
  • 348 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信