我无法连接到使用docker-compose
创建的mongodb容器mongodb配置(在docker-compose.yml中)如下:
mongodata:
image: mongo:3.0.4
volumes:
- /data/db
command: --break-mongo
mongo:
image: mongo:3.0.4
volumes_from:
- mongodata
ports:
- "27017:27017"
command: --smallfiles --rest --auth
当我跑步时:
docker-compose ps mongo
我得到了:
Name Command State Ports
------------------------------------------------------------------------------------
followit_mongo_1 /entrypoint.sh --smallfile ... Up 0.0.0.0:27017->27017/tcp
我无法连接mongo客户端,波纹管命令
docker-compose run mongo mongo
失败,这是错误:
MongoDB shell version: 3.0.4
connecting to: test
2015-11-10T17:10:32.735+0000 W NETWORK Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-11-10T17:10:32.741+0000 E QUERY Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed
at connect (src/mongo/shell/mongo.js:179:14)
at (connect):1:6 at src/mongo/shell/mongo.js:179
exception: connect failed
答案 0 :(得分:0)
尝试使用-p选项
发布27017容器的端口以进行托管docker-compose run -p 27017:27017 mongo mongo
我可以通过这种方式从主机访问mongo。
答案 1 :(得分:0)
问题是我在创建用户之前启用了需要用户身份验证的访问控制。所以我必须从mongo命令中删除--auth标志,创建管理员用户:
use admin
db.createUser(
{
user: "myUserAdmin",
pwd: "abc123",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
}
)
然后使用访问控制重新启动mongodb服务器:)
有关访问控制的详细信息,请参阅http://bit.ly/1QgVlW2