当auth启用时,MongoDB Docker容器拒绝连接
如果我没有auth设置我的容器例如)
docker run --name some-mongo -d -p 27017:27017 mongo
我可以从远程机器连接到我的mongoDB)
mongo [serverIP]
不过,我的问题是使用--auth
标志
以下文件:
docker run --name some-mongo -d -p 27017:27017 mongo --auth
> db.createUser({ user: 'foo', pwd: 'bar', roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] })
导致连接被拒绝:
$ mongo -u foo -p bar [serverIP] MongoDB shell version v3.4.9 connecting to: [serverIP] 2017-12-09T14:01:41.114-0600 W NETWORK [thread1] Failed to connect to [serverIP]:27017, in(checking socket for error after poll), reason: Connection refused 2017-12-09T14:01:41.115-0600 E QUERY [thread1] Error: couldn't connect to server [serverIP]:27017, connection attempt failed : connect@src/mongo/shell/mongo.js:237:13 @(connect):1:6 exception: connect failed
我仔细检查,端口看起来在服务器上打开:
$ netstat -tuplen (Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.) Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State User Inode PID/Program name ... tcp6 0 0 :::27017 :::* LISTEN 0 53238875 - ...
(Docker运行在debian数字海洋液滴上)
您需要指定--authenticationDatabase
标志
mongo --port 27017 -u "myUserAdmin" -p "abc123" --authenticationDatabase "admin"
看教程
- Docker:为什么我的设置松动?
- 在Mac上使用docker。 是否有可能使用docker-machine启动docker守护进程并传入参数?
- java.lang.IllegalStateException:找不到PropertySource,并且设置失败的fast属性失败
- 是否有可能将string发送到Docker容器中正在运行的进程?
- MAC | 在VirtualBox机器上从另一个应用程序部署在Docker上的应用程序
- 将Dockerfile转换为Bash脚本
- 从主机连接到docker容器中的mysql
- 为什么在Docker中需要“–expose”选项?
- 运行docker但是得到这个网站无法连接192.168.99.100拒绝连接