mongodb connection refused docker-compose

半腔热情 提交于 2019-12-04 05:21:29

You have to connect to mongodb:27017 instead of 127.0.0.1:27017 from your air_scout container.

The links for the air_scout container will create /etc/hosts entries for the redis and mongodb containers. The linked services will be reachable under those names.

See https://docs.docker.com/compose/compose-file/#/links

You do set an environment variable DATABASE_URL with the correct value mongodb:27017, but the error message still contains 127.0.0.1:27017. So it's trying to connect there instead of mongodb:27017. I have no experience with mongoid but I am guessing you should only leave the line with DATABASE_URL. If that does not work, use mongodb:27017

If you want to see what is going, docker exec into your running air_scout container

docker ps
# take the exact name of the air_scout container in the output
# i am guessing compose_air_scout but i might be off
docker exec -ti compose_air_scout /bin/bash
cat /etc/hosts
ping mongodb
# maybe try an interactive mongodb client
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!