Connect to database in docker container from local PC

174 views Asked by At

I have a MeteorJs application that I have deployed to Digital Ocean using MeteorUp. How can I connect to the MongoDB database using a MongoDB client from my local windows machine? I tried using MyDigitalOceanIP: 27017 but I am getting a "Connection failed" error.

Error:

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 container 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

Update: 9/2/2019: I am now getting a Exhausted available authentication methods error.

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

Here's what I have tried.

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. 
1

There are 1 answers

1
Mikkel On

There are a couple of possibilities:

  1. The port 27017 isn't publicly available (see firewall rules to open ports)
  2. The machine doesn't have a public IP address

Check your firewall rules, and make sure you are connecting to the public ip (not the internal IP)