2

I am trying to connect to my docker mongo image, I installed mongodb in local, and added the mongodb bin path to windows path environment variable. And I am doing below steps

cd <docker-location>

docker login

docker ps

-- to check already mongo running

docker pull myrepo/mymongo-image:1.0
docker run -p 27017:27017 -d --net=host --name=mytestDB myrepo/mymongo-image:1.0

docker logs mytestDB 

Output: MongoDB starting : pid=6 port=27017 dbpath=/data/db 64-bit host=moby docker ps Output:

CONTAINER ID        IMAGE                     COMMAND                  CREATED             STATUS              PORTS               NAMES
34598734598        myrepo/mymongo-image:1.0   "/bin/sh -c /usr/bin/"   12 hours ago        Up About a minute                       mytestDB

start mongo in local:

mongo --port 27017

But I am getting error like this:

MongoDB shell version: 3.2.1
connecting to: 127.0.0.1:27017/test
2016-10-13T20:04:12.273+0530 W NETWORK  [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:10061 No connection could be made because the target machine actively refused it.
2016-10-13T20:04:12.277+0530 E QUERY    [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect@src/mongo/shell/mongo.js:226:14
@(connect):1:6

exception: connect failed

Please let me know where I did mistake.

2
  • when you run "docker ps" your ports column is empty ...is this a copy paste error, or is that how it actually displays? Could your localhost not have that port open somehow? Commented Oct 13, 2016 at 16:23
  • I also observed that, it not showing port in 'docker ps' command. Commented Oct 14, 2016 at 1:24

2 Answers 2

7

I got solution, I like to share it.

'--noauth --bind_ip=0.0.0.0' options are missed in my commands.

This is the blog bring me out.

Tutorial: Setting up MongoDB Image Instance with Docker Toolbox

Sign up to request clarification or add additional context in comments.

1 Comment

the link which @sun mention above help me alot
0

if you have already installed docker-toolbox and you have created an image but unable to visualize your mongodb database through robo3t

for this illustration i created my image with command

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

Note: since 27017 is port for mongodb

Open up VirtualBox. Right click the "Default" machine.

Select settings from the menu.

Choose the Network tab in the settings menu.

Choose port forwarding at the bottom of the network option.

Click the plus icon to the right of the port forwarding menu.

Make the new entry with the name mongo.

Protocol should be TCP. Host and Guest IP can be left empty.

Set the host port to the port you make use in creating your

image I made use of port 27017. Set the guest port to 27017.

install robo3t from http://robomongo.org/download.html

click icon below file tab to create a new connection

Choose to create a new connection.

Name your connection and set the address to localhost and port to the port you set your Host port too in VirtualBox, in my case is 27017

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.