Can not connect mongodb run in docker-compose
MONGO_URL=mongodb://db:27017/500ae_cms
error:
MongoDB connection error: mongodb://db:27017/500ae_cms
.
MongoNetworkError: failed to connect to server [db:27017] on first connect [Error: getaddrinfo ENOTFOUND db at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:60:26) { name: 'MongoNetworkError', errorLabels: [Array], }]
For your db service you expose port 27775 but in your app you try to connect to 27017.
Docker resolves the service name in an IP address but this fails here (too?)
failed to connect to server [db:27017];;; getaddrinfo ENOTFOUND db
should at least be something like:
failed to connect to server [db:27017] on first connect [Error: connect ECONNREFUSED 17.19.0.2:27017
Can you try running nslookup db
from the api container? If that resolves, then it might be an issue with your mongo driver.
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.