MongoDB Docker容器在启用auth时拒绝连接

时间:2017-12-09 20:27:23

标签: 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 Digital Ocean Droplet运行)

1 个答案:

答案 0 :(得分:0)

您需要指定docker run -it -v /place/to/save/file:/store myapp /bin/bash cp /result.png /store/ 标志

--authenticationDatabase

请参阅tutorial