蒙戈這是我的搬運工,撰寫文件:連接的NodeJS並與碼頭工人
version: "2"
services:
rest-api:
build: .
ports:
- "3007:3007"
links:
- mongo
mongo:
image: mongo
volumes:
- /data/mongodb/db:/data/db
ports:
- "27017:27017"
這是我Dockerfile:
FROM mhart/alpine-node:latest
RUN rm -rf /tmp/node_modules
ADD package.json /tmp/package.json
RUN cd /tmp && npm install
RUN mkdir -p /opt/app && cp -a /tmp/node_modules /opt/app/
WORKDIR /opt/app
ADD . /opt/app
EXPOSE 3007
CMD ["node", "index.js"]
當我運行的圖像,節點不能夠連接到mongo:
MongoError: failed to connect to server [localhost:27017] on first connect
什麼可能是錯誤的?我怎樣才能調試呢?
更新:
在我節點應用程序我有:
let connection = mongoose.connect('mongodb://localhost/myapp');