使用Docker将NodeJS MongoClient连接到localhost mongodb

时间:2017-11-01 13:34:18

标签: node.js mongodb docker dockerfile

macOS Sierra

MongoDB Enterprise> db.version()=> 3.4.7

Node.js 8.9.0

Docker Image Inspect => gist

我有这个代码昨天在Node中运行,然后在Docker容器中运行,今天在Docker容器中运行时出现以下容器错误输出。这些错误引用了一个拓扑问题,该问题是由昨天和今天之间的事情触发的我不知道这意味着什么。我唯一能想到的是将nvm从8.2.1切换到8.9.0。转回来没有帮助。添加重新连接参数也没有帮助。任何想法都将不胜感激。

更新:如果我将uri更改为azure cosmosdb实例,则会运行相同的代码。所以它只是连接到本地mongodb的连接字符串,并不想连接。再次,昨天跑,只是更新。不知道这里发生了什么......

Hi mongodb://localhost:27017/visafrenchtech
MongoDB connecting to mongodb://localhost:27017/visafrenchtech
MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017]
    at Pool.<anonymous> (/app/node_modules/mongodb-core/lib/topologies/server.js:336:35)
    at emitOne (events.js:116:13)
    at Pool.emit (events.js:211:7)
    at Connection.<anonymous> (/app/node_modules/mongodb-core/lib/connection/pool.js:280:12)
    at Object.onceWrapper (events.js:317:30)
    at emitTwo (events.js:126:13)
    at Connection.emit (events.js:214:7)
    at Socket.<anonymous> (/app/node_modules/mongodb-core/lib/connection/connection.js:187:49)
    at Object.onceWrapper (events.js:315:30)
    at emitOne (events.js:116:13)

Node.js输出

Hi mongodb://localhost:27017/visafrenchtech
MongoDB connecting to mongodb://localhost:27017/visafrenchtech
DB mongodb://localhost:27017/visafrenchtech connected
{ _id: 59f8ab91277b785b1c354f05,
  url: 'http://visa.lafrenchtech.com/10/find-your-future-employer-in-france-french-tech-visa',
  logo: 'https://d25e16a427ed3ce77d27-76b466cd72f6b3a6e7219a8a02851d8e.ssl.cf1.rackcdn.com/files/59382428ff3935425ca91516/size_5_1001pharmaciesjpg.jpg',
  company_url: 'http://www.1001pharmacies.com/',
  company_name: '1001 Pharmacies',
  industry: '#HealthTech #Retail',
  location: 'French Tech Montpellier',
  number_employees: 28,
  description: '1001Pharmacies.com is a marketplace dedicated to the online sale of health / beautyproducts. We are intermediaries between Internet users and French pharmacies for online sales.',
  job_offers: 'Job Offers',
  job_offers_link: 'http://www.welcometothejungle.co/companies/1001pharmacies',
  Twitter: '@1001pharma',
  Facebook: 'https://www.facebook.com/1001Pharmacies/',
  Instagram: 'https://www.instagram.com/1001pharmacies/?hl=fr',
  Youtube: 'https://www.youtube.com/channel/UChLwpSs9nHs2xbYdbNEJqQg',
  address: 'Parc Eureka 256 r Thor, 34000 MONTPELLIER',
  tranche: '21 - 40' }

这是DockerFile

FROM mhart/alpine-node:8
WORKDIR /app
COPY package.json ./
RUN npm install
COPY . ./
EXPOSE 4000
CMD [ "node", "index.js"]

0 个答案:

没有答案