【问题标题】:Connect to database in docker container from local PC从本地 PC 连接到 docker 容器中的数据库
【发布时间】:2023-03-19 08:35:01
【问题描述】:

我有一个使用 MeteorUp 部署到 Digital Ocean 的 MeteorJs 应用程序。如何使用本地 Windows 机器上的 MongoDB 客户端连接到 MongoDB 数据库?我尝试使用 MyDigitalOceanIP: 27017 但我收到“连接失败”错误。

错误:

Connection failed.
SERVER [MyDigitalOceanIP:27017] (Type: UNKNOWN) CONNECTING
Details:
Timed out after 5000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=MyDigitalOceanIP:27017, type=UNKNOWN, state=CONNECTING}]

docker 容器 ls

CONTAINER ID        IMAGE                                  COMMAND                  CREATED             STATUS              PORTS                        NAMES
91502fe2c115        mup-todousingreactandmeteorjs:latest   "/bin/sh -c 'bash $M…"   12 minutes ago      Up 12 minutes       0.0.0.0:80->80/tcp           ToDoUsingReactAndMeteorJs
2d4be51b46a2        mongo:3.4.1                            "/entrypoint.sh mong…"   21 minutes ago      Up 21 minutes       127.0.0.1:27017->27017/tcp   mongodb

更新:2019 年 9 月 2 日: 我现在收到 Exhausted available authentication methods 错误。

SSH Tunnel error: authentication failed: Exhausted available authentication methods    
Stacktrace:
|_/ SSH Tunnel error: authentication failed: Exhausted available authentication methods
|____/ SSH Tunnel error: Exhausted available authentication methods

这是我尝试过的。

a. Copied public key from my local machine to ~/.ssh/authorized_keys folder in my Digital Ocean VM.
b. updated PasswordAuthentication, ChallengeResponseAuthentication, PubkeyAuthentication to yes in /etc/ssh/sshd_config.
c. In my local PC, created a standard connection with 
c.1. server localhost and port 27017, 
c.2. Authentication Mode None
c.3. Use SSL protocol to connect as unchecked. 
c.4. Use SSH tunnel to connect with ssh address as my public IP, port 22, SSH user name as the root user name. I tried with both ssh auth mode as private key(in OpenSSH format) and password. 

【问题讨论】:

    标签: mongodb docker meteor digital-ocean meteor-up


    【解决方案1】:

    有几种可能:

    1. 端口 27017 不公开(请参阅防火墙规则以打开端口)
    2. 机器没有公共 IP 地址

    检查您的防火墙规则,并确保您连接到公共 IP(不是内部 IP)

    【讨论】:

    • 谢谢@Mikkel。我决定设置 Adminer,这样我就不必在我的 Droplet 上打开输入端口了。
    猜你喜欢
    • 2021-05-22
    • 1970-01-01
    • 1970-01-01
    • 2021-12-14
    • 1970-01-01
    • 1970-01-01
    • 2017-10-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多