Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No suitable servers found (serverSelectionTryOnce set): [connection refused calling ismaster on '127.0.0.1:27017'] #932

Closed
anggakes opened this issue May 12, 2017 · 12 comments

Comments

@anggakes
Copy link

anggakes commented May 12, 2017

Info:

  • Docker version (Docker version 17.03.1-ce, build c6d412e):
  • Laradock commit (8a13ae1):
  • System info (Mac):
  • System info sierra:

Issue:

I test this :
$client = new Client();

    $collection = (new \MongoDB\Client)->example->users;

    $insertOneResult = $collection->insertOne([
        'username' => 'admin',
        'email' => 'admin@example.com',
        'name' => 'Admin User',
    ]);

    printf("Inserted %d document(s)\n", $insertOneResult->getInsertedCount());

    var_dump($insertOneResult->getInsertedId());

Expected behavior:

result error :
No suitable servers found (serverSelectionTryOnce set): [connection refused calling ismaster on '127.0.0.1:27017']

this is my docker PS :
` Name Command State Ports

laradock_applica /true Exit 0
tions_1
laradock_mariadb docker- Up 0.0.0.0:33061->3306/tcp
_1 entrypoint.sh
mysqld
laradock_mongo_1 docker- Up 0.0.0.0:27018->27017/tcp
entrypoint.sh
mongod
laradock_nginx_1 nginx Up 0.0.0.0:4430->44
3/tcp, 0.0.0.0:8
100->80/tcp, 0.0
.0.0:820->820/tc
p
laradock_php- docker-php- Up 9000/tcp
fpm_1 entrypoint php-
fpm
laradock_workspa /sbin/my_init Up 0.0.0.0:2222->22
ce_1 /tcp `

@bestlong
Copy link
Member

Hi @anggakes By you provided info laradock_mongo_1 show out map port 0.0.0.0:27018,

change your php project config to fit. or revert .env set MONGODB_PORT=27017

@anggakes
Copy link
Author

thanks for answer, I have try that, and not fix my problem sir.

I just fix my problem because I can connect my mongo container with robomongo,
so what I do is :

  1. from workspace container I get my host IP, that is 172.21.0.1 with port 27018
  2. on my php script, I connect my mongodb Client class with host 172.21.0.1:27018

the problem is, this is not dynamic.

@bestlong
Copy link
Member

bestlong commented May 13, 2017

@anggakes Sorry i made a mistake, your php project is run in php-fpm container.
so, to connect Mongo service, your php project config hostname is "mongo" and port is 27017.

@Mahmoudz
Copy link
Member

@bestlong please check your Gitter messages : )

@anggakes
Copy link
Author

@bestlong thanks for the answer friend :D

@sajidunnar
Copy link

Hey guys, having the same issue all docker instances were fine for some reason I did docker rese and then getting the same problem.

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
***** ****** "docker-entrypoint..." 43 minutes ago Up 39 minutes 0.0.0.0:27012->27017/tcp laradock_mongo_1

in my .env file I have set my port to 27012 but either with robo 3t or via shell I cant connect as get following errors

(master) % mongo mongodb://127.0.0.1:27012 *******************
MongoDB shell version v3.6.0
connecting to: mongodb://127.0.0.1:27012
2017-12-11T21:56:29.153+0500 E QUERY [thread1] Error: network error while attempting to run command 'isMaster' on host '127.0.0.1:27012' :
connect@src/mongo/shell/mongo.js:251:13

even with laravel app ( same code and env file with correct port ) I got this error

[MongoDB\Driver\Exception\ConnectionTimeoutException]
No suitable servers found (serverSelectionTryOnce set): [connection refused calling ismaster on 'mongo:27017']

On gogole search they recommending to bind the ip but I Am not sure how I can do that

@tomjamon
Copy link

Hey, I just had the same issue on my Vagrant VM, Ubuntu based.

No suitable servers found (serverSelectionTryOnce set): [connection refused calling ismaster on '127.0.0.1:27017']

I'm definitly not an expert and i'm not sure it's the same problem, but here is how i fixed it on my case :
https://stackoverflow.com/a/51553257/3132123 (rights problem, i dunno why)

@stus3y
Copy link

stus3y commented Nov 12, 2019

@bestlong that works for me ! Thanks !

@stale
Copy link

stale bot commented Feb 10, 2020

Hi 👋 this issue has been automatically marked as stale 📌 because it has not had recent activity 😴. It will be closed if no further activity occurs. Thank you for your contributions ❤️.

@stale stale bot added the Stale label Feb 10, 2020
@stale
Copy link

stale bot commented Mar 2, 2020

Hi again 👋 we would like to inform you that this issue has been automatically closed 🔒 because it had not recent activity during the stale period. We really really appreciate your contributions, and looking forward for more in the future 🎈.

@stale stale bot closed this as completed Mar 2, 2020
@marcnewton
Copy link

SELinux (CentOS7/8) can cause this error, applying the following rule may resolve it:

setsebool -P httpd_can_network_connect_db 1

@Cqmille
Copy link

Cqmille commented Nov 20, 2020

Hi everyone,

Had the same issue here, Docker runs on Windows. Above solutions didn't work but i've been able to fix it with hostname host.docker.internal

Found solution here : https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants