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

我在无法连接到本地托管的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



回首忆惘然
浏览 349回答 1
1回答

FFIVE

在docker-compose.yml中配置网络配置后,此问题已解决,该问题是mysql和Docker容器在不同的子网中运行。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java