从远程服务器连接到docker mongo实例

时间:2016-08-01 18:48:33

标签: mongodb docker

这应该很简单,但我找不到任何答案 我在服务器上安装了docker 我正在运行mongo

docker run --name some-mongo -d mongo

我有一个用户

$ docker exec -it some-mongo mongo admin
connecting to: admin
> db.createUser({ user: 'jsmith', pwd: 'some-initial-password', roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] });
Successfully added user: {
    "user" : "jsmith",
    "roles" : [
        {
            "role" : "userAdminAnyDatabase",
            "db" : "admin"
        }
    ]
}

当我尝试从其他服务器连接时

mongo my-server.com:27017/admin -u jsmith -p some-initial-password

我有

MongoDB shell version: 3.2.0
connecting to: infra1.host.com:27017/admin
2016-08-01T19:06:08.409+0100 W NETWORK  [thread1] Failed to connect to 54.93.113.11:27017, reason: errno:61 Connection refused
2016-08-01T19:06:08.410+0100 E QUERY    [thread1] Error: couldn't connect to server my-server.com:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:226:14
@(connect):1:6

1 个答案:

答案 0 :(得分:3)

只需重定向mongo端口:

docker run --name some-mongo -p 27017:27017 -d mongo