Docker RabbitMQ Spring java.net.UnknownHostException:rabbitmq:名称或服务未知

问题描述 投票:1回答:1

我正在尝试在Docker上部署Spring Server。 Spring服务器正在连接到在另一个应用程序中运行的RabbitMQ服务器。连接到rabbitmq时出现错误。我在我的application.properties中添加了主机,但没有工作。比作为环境变量添加到应用程序容器中仍然无效。我还重建了jar并更改了图像版本。

version: '3'

services:
  rabbitmq:
    image: rabbitmq:management
    ports:
      - "5672:5672" #JMS Port
      - "15672:15672" #Management Port - default user:pass = guest:guest

  db:
    image: mysql:5.7.22
    environment:
      MYSQL_ROOT_PASSWORD: "root"
      MYSQL_DATABASE: "hospital"
      MYSQL_PASSWORD: "root"
    ports:
      - "3306:3306"
    networks:
      - mysql_bridge
    restart: always

  springboot-docker-compose-app-container:
    image: app-image
    build:
      context: ./
      dockerfile: Dockerfile
    environment: # Pass environment variables to the service
      SPRING_DATASOURCE_URL: jdbc:mysql://db:3306/hospital?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false&allowPublicKeyRetrieval=true
      SPRING_DATASOURCE_USERNAME: root
      SPRING_DATASOURCE_PASSWORD: root
      SPRING_RABBITMQ_HOST: rabbitmq
    depends_on:
      - rabbitmq
      - db
    volumes:
      - /data/VerzorgerSOAP
    ports:
      - "8080:8080"
    networks:
      - mysql_bridge
      - rabbiy_mq

networks:
  mysql_bridge:
  rabbiy_mq: 

也是这是我的application.properties

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.generate-ddl=true
spring.datasource.url = jdbc:mysql://db:3306/hospital?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false&allowPublicKeyRetrieval=true
spring.jpa.hibernate.ddl-auto = update
spring.datasource.username = root
spring.datasource.password = root
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS = false

server.ssl.enabled=false

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
spring.jpa.properties.hibernate.globally_quoted_identifiers=true

spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true
spring.rabbitmq.host= rabbitmq

这是我得到的错误

org.springframework.amqp.AmqpIOException: java.net.UnknownHostException: rabbitmq
spring spring-boot docker rabbitmq
1个回答
0
投票

[dockercompose文件中的Rabbitmq网络配置丢失:

rabbitmq:
    image: rabbitmq:management
    ports:
      - "5672:5672" #JMS Port
      - "15672:15672" #Management Port - default user:pass = guest:guest
    networks:
      - rabbiy_mq

@ david-maze建议的另一种解决方案是删除所有networks

© www.soinside.com 2019 - 2024. All rights reserved.