简体   繁体   中英

How to access RabbitMQ service (on host machine) from Spring boot docker container running on same machine

Environment Details

Windows 10

Docker Desktop

Spring Boot ( Using it inside Container)

RabbitMQ ( Installed on my windows machine as a Service)

I would like to access RabbitMQ service from the Spring Boot Container. I provided below properties inside application.properties

batch.rabbitmq.host=localhost
batch.rabbitmq.port=5672
batch.rabbitmq.username=guest
batch.rabbitmq.password=guest
server.port=8083

I am running my spring boot app as

docker run -p 8083:8083 dockerdemo

I can access the RabbitMQ management console using localhost:15672 but my spring boot application unable to connect it.

It throw connection

java.net.ConnectException: Connection refused (Connection refused)

What do I need to change, Please suggest.

From inside the container localhost is resolved to inside the container not the physical host machine. So you need to change the setting to something like this

batch.rabbitmq.host=[HOST_NAME OR IP Address]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM