何らかの理由で、このトピックの他のstackoverflow投稿を使用して動作させることができませんでした。 私は得ています: MongoError: failed to connect to server [localhost:27017] on first connect
。ノードを使用してMongoErrorを取得するmongoコンテナに接続する
私は私のドッキングウィンドウコンテナを開始し、モンゴが働いていた場合にチェック:
$ docker run --name my-mongo -d mongo
$ docker exec -it my-mongo bash
# mongo
MongoDB shell version v3.4.2
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.2
Server has startup warnings:
2017-03-19T01:23:53.047+0000 I STORAGE [initandlisten]
2017-03-19T01:23:53.047+0000 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2017-03-19T01:23:53.047+0000 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2017-03-19T01:23:53.290+0000 I CONTROL [initandlisten]
2017-03-19T01:23:53.290+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-03-19T01:23:53.290+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2017-03-19T01:23:53.290+0000 I CONTROL [initandlisten]
> db.col.insert({"a":1})
> db.col.find()
{ "_id" : ObjectId("58cde45479f772a8ea882ee1"), "a" : 1 }
私は私のOSXのターミナル内のノードを開始し、接続しようとした後、終了しました:
$ node
> var mongoose = require("mongoose");
> mongoose.connect("mongodb://localhost:27017");
mongoose {...}
> MongoError: failed to connect to server [localhost:27017] on first connect ...
私は他の多くのURLを試してみました:
mongoose.connect("mongodb://localhost:27017/test");
mongoose.connect("mongodb://localhost/test");
mongoose.connect("mongodb://127.0.0.1:27017");
docker上で実行されているmongodbコンテナに接続しようとしていますnodejを使用して接続しようとしています。どうすればこれを達成できますか?
https://docs.docker.com/docker-for-mac/networking/#i-want-to-connect-to-a-container-from-the-mac –