Asked Mar 12th, 2019 2:44 a.m. 478 0 0
  • 478 0 0
+1

Failed to connect to server [mongodb:27017] on first connect

Share
  • 478 0 0

Dockerfile

FROM node:latest

WORKDIR /usr/src/app/

USER root

COPY package.json ./

RUN npm install --silent --no-cache

COPY ./ ./

EXPOSE 7001

CMD npm run dev

Docker compose

version: "3"

services:
  app_dev:
    ports:
      - 10000:10000
      - 7001:7001
    build:
      context: ../
      dockerfile: Dockerfile.dev
    container_name: app_dev
    restart: always
    depends_on:
      - mongo
    volumes:
      - ../app:/usr/src/app/app
      - ../config:/usr/src/app/config
    networks:
      - phuhuong
  mongo:
    container_name: mongo_dev
    env_file: ../.env
    environment:
      MONGO_INITDB_ROOT_USERNAME: ${MONGO_INITDB_ROOT_USERNAME}
      MONGO_INITDB_ROOT_PASSWORD: ${MONGO_INITDB_ROOT_PASSWORD}
      MONGO_INITDB_DATABASE: ${MONGO_INITDB_DATABASE}
    image: mongo:latest
    restart: always
    ports:
      - "27017:27017"
    volumes:
      - ../mongo/data:/data/db:Z
      - ../mongo/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
    command: mongod --smallfiles
    networks:
      - phuhuong

networks:
  phuhuong:

Mongosee connect

client: {
      url: 'mongodb://user:pass@mongo:27017/database',
      options: {
        autoReconnect: true,
        reconnectTries: Number.MAX_VALUE,
        bufferMaxEntries: 0,
        useCreateIndex: true,
        useNewUrlParser: true,
      },
    },

Mình đang sử dụng cấu hình này trên ubuntu 18, hiện chuyển sang windows 10 thì không thể kết nối được database mongo, cũng thử nhiều cách, nhưng k rõ nguyên nhân do đâu?

Mar 12th, 2019 2:51 a.m.

Bạn kiểm tra xem cái service mongo nó đang running hay là không trước đã. Sau đó xem logs của cái service mongo xem nó có bắn gì ra không. Có thể mongo không chạy, không connect được database cũng có thể do sai username/password của db chẳng hạn... Nhiều lắm! Bạn check log trước chứ mọi người xem cấu hình rồi đoán mò lỗi thì cũng không hay lắm.

0
| Reply
Share
Mar 12th, 2019 3:02 a.m.

@huukimit Mình đọc log mongo container nhưng k hiểu lỗi lắm, b xem qua giúp.

2019-03-12T02:59:28.544+0000 I CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2019-03-12T02:59:28.546+0000 I CONTROL  [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=281f352eb7bb
2019-03-12T02:59:28.546+0000 I CONTROL  [initandlisten] db version v4.0.6
2019-03-12T02:59:28.546+0000 I CONTROL  [initandlisten] git version: caa42a1f75a56c7643d0b68d3880444375ec42e3
2019-03-12T02:59:28.546+0000 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
2019-03-12T02:59:28.546+0000 I CONTROL  [initandlisten] allocator: tcmalloc
2019-03-12T02:59:28.546+0000 I CONTROL  [initandlisten] modules: none
2019-03-12T02:59:28.546+0000 I CONTROL  [initandlisten] build environment:
2019-03-12T02:59:28.546+0000 I CONTROL  [initandlisten]     distmod: ubuntu1604
2019-03-12T02:59:28.546+0000 I CONTROL  [initandlisten]     distarch: x86_64
2019-03-12T02:59:28.546+0000 I CONTROL  [initandlisten]     target_arch: x86_64
2019-03-12T02:59:28.546+0000 I CONTROL  [initandlisten] options: { net: { bindIpAll: true }, security: { authorization: "enabled" }, storage: { mmapv1: { smallFiles: true } } }

2019-03-12T02:59:28.550+0000 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=478M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=
snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=(recovery_progress),
2019-03-12T02:59:29.276+0000 E STORAGE  [initandlisten] WiredTiger error (17) [1552359569:276435][1:0x7fa2d35b3a40], connection: __posix_open_file, 715: /data/db/WiredTiger.wt: handle-open: open: File exists Raw: [1552359569:276435][1:0x7fa2d35b3a40],
 connection: __posix_open_file, 715: /data/db/WiredTiger.wt: handle-open: open: File exists
2019-03-12T02:59:29.282+0000 I STORAGE  [initandlisten] WiredTiger message unexpected file WiredTiger.wt found, renamed to WiredTiger.wt.456
2019-03-12T02:59:29.284+0000 E STORAGE  [initandlisten] WiredTiger error (1) [1552359569:284034][1:0x7fa2d35b3a40], connection: __posix_open_file, 715: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted Raw: [1552359569:284034][1:0x7fa
2d35b3a40], connection: __posix_open_file, 715: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted
2019-03-12T02:59:29.298+0000 E STORAGE  [initandlisten] WiredTiger error (17) [1552359569:298459][1:0x7fa2d35b3a40], connection: __posix_open_file, 715: /data/db/WiredTiger.wt: handle-open: open: File exists Raw: [1552359569:298459][1:0x7fa2d35b3a40],
 connection: __posix_open_file, 715: /data/db/WiredTiger.wt: handle-open: open: File exists
2019-03-12T02:59:29.306+0000 I STORAGE  [initandlisten] WiredTiger message unexpected file WiredTiger.wt found, renamed to WiredTiger.wt.457
2019-03-12T02:59:29.309+0000 E STORAGE  [initandlisten] WiredTiger error (1) [1552359569:309146][1:0x7fa2d35b3a40], connection: __posix_open_file, 715: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted Raw: [1552359569:309146][1:0x7fa
2d35b3a40], connection: __posix_open_file, 715: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted
2019-03-12T02:59:29.326+0000 E STORAGE  [initandlisten] WiredTiger error (17) [1552359569:326492][1:0x7fa2d35b3a40], connection: __posix_open_file, 715: /data/db/WiredTiger.wt: handle-open: open: File exists Raw: [1552359569:326492][1:0x7fa2d35b3a40],
 connection: __posix_open_file, 715: /data/db/WiredTiger.wt: handle-open: open: File exists
2019-03-12T02:59:29.332+0000 I STORAGE  [initandlisten] WiredTiger message unexpected file WiredTiger.wt found, renamed to WiredTiger.wt.458
2019-03-12T02:59:29.334+0000 E STORAGE  [initandlisten] WiredTiger error (1) [1552359569:334743][1:0x7fa2d35b3a40], connection: __posix_open_file, 715: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted Raw: [1552359569:334743][1:0x7fa
2d35b3a40], connection: __posix_open_file, 715: /data/db/WiredTiger.wt: handle-open: open: Operation not permitted
2019-03-12T02:59:29.337+0000 W STORAGE  [initandlisten] Failed to start up WiredTiger under any compatibility version.
2019-03-12T02:59:29.337+0000 F STORAGE  [initandlisten] Reason: 1: Operation not permitted
2019-03-12T02:59:29.337+0000 F -        [initandlisten] Fatal Assertion 28595 at src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp 704
2019-03-12T02:59:29.337+0000 F -        [initandlisten]

***aborting after fassert() failure
+1
| Reply
Share
Viblo
Let's register a Viblo Account to get more interesting posts.