How to access your OpenShift MongoDB database remotely on OS-X

I recently started playing around with Redhat’s Openshift PaaS and installed the MongoDB and RockMongo cartridges on my application. My use case was just to leverage the Openshift platform to run my MongoDB instance for me, and I really was ready (nor needing) to push an actual application out to the application running @ openshift; instead I just wanted my local Java program to leverage the remote MongoDB instance, pump some data into it and then view it in Rockmongo (also running on the app at openshift).

Turns out you can enable this by enabling port forwarding locally on the computer you want to connect from. This is on OS-X:

  • First ensure that your SSH key is available for use by the command we will run: “ssh-add /path/to/your/openshift/ssh.key” This should be the key that you created when you initially signed up for Openshift
  • Attempt to run the port forwarding enable command “rhc port-forward -a [yourAppName] -l [yourOpenShiftLoginId]“, it will prompt you for your openshift credentials, then will likely output something like the below:

Checking available ports...

Binding httpd ->…
Binding mongod ->…

Use ctl + c to stop

bind: Can’t assign requested address
channel_setup_fwd_listener: cannot listen to port: 27017
bind: Can’t assign requested address
channel_setup_fwd_listener: cannot listen to port: 8080
Could not request local forwarding.

  • The above error is because we need to now enable loopback aliases for each failed 127.x address listed above (those addresses will be different in your output above). To do this run the following for EACH loopback that failed: “sudo ifconfig lo0 alias 127.x.x.x“. Note that even after running this, make sure you already don’t have something else local bound on those ports (i.e. a local dev mongodb instance or something else on 8080)
  • After you add the loopback aliases re-run the port forwarding command above, this time it should successfully complete. If you go to https://127.x.x.x:8080 your request will be going directly to your openshift instance.
  • You can also now connect to your mongodb instance programmatically as well just using the new address:ports forwarded above plus the appropriate credentials
  • Interestingly enough the port forwarding goes over an SSH tunnel to your app there, and it appears that Openshift itself uses AWS!
Some relevant links to help you out which also helped me:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s