2017-07-22 135 views
0

我想在我自己的機器上與mongo數據庫在同一臺機器上設置一個解析服務器。按照這個教程,https://medium.com/@dmathewwws/guide-to-building-your-own-parse-server-aad6568b743d解析mongo數據庫無法連接到服務器

但我有一些問題,解析抱怨不能連接到我的數據庫。

2017-07-22T17:41:39.888Z - Error generating response. { MongoError: failed to connect to server [localhost:27017] on first connect 
at Pool.<anonymous> (/parse/node_modules/mongodb-core/lib/topologies/server.js:313:35) 
at emitOne (events.js:115:13) 
at Pool.emit (events.js:210:7) 
at Connection.<anonymous> (/parse/node_modules/mongodb-core/lib/connection/pool.js:260:12) 
at Object.onceWrapper (events.js:318:30) 
at emitTwo (events.js:125:13) 
at Connection.emit (events.js:213:7) 
at Socket.<anonymous> (/parse/node_modules/mongodb-core/lib/connection/connection.js:162:49) 
at Object.onceWrapper (events.js:316:30) 
at emitOne (events.js:115:13) 
name: 'MongoError', 
message: 'failed to connect to server [localhost:27017] on first connect' } 

蒙戈DB似乎對27017

Proto Recv-Q Send-Q Local Address   Foreign Address   State  User  Inode  PID/Program name 
tcp  0  0 127.0.0.1:27017   0.0.0.0:*    LISTEN  112  24024  3200/mongod 

運行,我還可以通過命令行太連接,

mongo mongodb://username:[email protected]:27017/myDB 
MongoDB shell version: 3.2.15 
connecting to: mongodb://username:[email protected]:27017/myDB 
> show collections 
test 
> 

這裏是我的船塢文件設置。

environment: 
    ... 
    DATABASE_URI: mongodb://username:[email protected]:27017/myDB 
mongo: 
    image: mongo:3.2.15 
    expose: 
    - "27017" 
    volumes: 
    - /mnt/database/mongodb 

mongodb實際上坐在另一個卷中,具有此權限。

[email protected]:/mnt/database# ls -lh 
total 20K 
drwx------ 2 root root  16K Jul 20 02:34 lost+found 
drwxr-xr-x 4 mongodb mongodb 4.0K Jul 22 17:10 mongodb 

在此先感謝!

回答

0

我的工作是用容器鏈接替換localhost。我發現這個tutorial有幫助。

parse-server: 
    ... 
    environment: 
     ... 
     DATABASE_URI: mongodb://mongo:27017/myDB 
    links: 
     - mongo:mongo 
mongo: 
    image: mongo 
    volumes: 
    - /mnt/database/mongodb 

TLDR:tutorial:搬運工,compose.yml

mongo-parse-server: 
    image: mongo 
parse-server: 
    image: yongjhih/parse-server 
    links: 
     - mongo-parse-server:mongo 
    environment: 
     - APP_ID=LWP_APP 
     - MASTER_KEY=DA5AC2FF-8F44-4082-8E5C-A78F2A96ACAD 
     - FILE_KEY=1DAFE373-5D8A-4E7A-AD05-67C3BA0EDB64 
    ports: 
     - 1337:1337 
parse-dashboard: 
    image: yongjhih/parse-dashboard 
    environment: 
     - PARSE_DASHBOARD_CONFIG={"apps":[{"appId":"LWP_APP","serverURL":"http://192.168.99.100:1337/parse","masterKey":"DA5AC2FF-8F44-4082-8E5C-A78F2A96ACAD","appName":"LWP"}],"users":[{"user":"foo","pass":"bar"}]} 
     - PARSE_DASHBOARD_ALLOW_INSECURE_HTTP=1 
    ports: 
     - 4040:4040 
+0

注:請勿張貼#2 –

+0

感謝您的應用程序鍵,關鍵是從教程 – Wesley

+0

我複製/粘貼看到。 Github上還有高級用法。 https://github.com/yongjhih/docker-parse-server/blob/master/ADVANCE.md –

相關問題