description to {type=UNKNOWN, servers=[{address=127.0.0.1:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException...: Exception opening socket}, caused by {java.net.ConnectException: Connection refused}}]
原因分析
docker是一个虚拟环境...,127.0.0.1和localhost指的是虚拟环境内部,而不是外部宿主机,所以无法这样访问....解决方案
对于mac和windows,可以使用host.docker.internal替换127.0.0.1,如 mongodb://host.docker.internal:27017
对于Linux...docker network create -d bridge --subnet 192.168.0.0/24 --gateway 192.168.0.1 localNet
使用192.168.0.1替换