无法连接到本地主机Mongodb docker-compose设置

时间:2019-04-15 14:55:12

标签: node.js mongodb docker

我无法通过客户端(例如Robot 3T)连接到我的mongoDB实例。它甚至没有机会进行身份验证。

这是我的docker-compose文件:

version: '3'
services:
  frontend:
    build:
      context: panel_front_end/
    ports:
      - 8080:80
    environment:
      - NODE_ENV=local
    restart: always
    networks:
      - nginx_network
  backend:
    build:
      context: panel_back_end/
      args:
        - SSH_PRIVATE_KEY
    environment:
      - NODE_ENV=local
      - HTTPS=true
    ports:
      - "3000:3000"
      - "8443:8443"
    volumes:
      - ./panel_back_end/ssl:/usr/src/app/ssl
    restart: always
    networks:
      - nginx_network
    depends_on:
      - mongodb
    links:
      - mongodb
  mongodb:
    build:
      context: mongo/
    ports:
      - "27017:27017"
    expose:
      - 27017
    volumes:
      - ./data/db:/data/db
      - ./backup:/backup
    environment:
      # provide your credentials here
      - MONGODB_ADMIN_USER=${MONGODB_ADMIN_USER}
      - MONGODB_ADMIN_PASS=${MONGODB_ADMIN_PASS}
      - MONGODB_APPLICATION_DATABASE=${MONGODB_APPLICATION_DATABASE}
      - MONGODB_APPLICATION_USER=${MONGODB_APPLICATION_USER}
      - MONGODB_APPLICATION_PASS=${MONGODB_APPLICATION_PASS}
networks:
  nginx_network:
    external: true

我愿意docker ps,这是输出:

ef695029ff3f        control-panel_backend    "/bin/sh -c ./entryp…"   5 minutes ago       Restarting (1) 22 seconds ago                                       control-panel_backend_1
d397eac69a70        control-panel_frontend   "/bin/sh -c ./entryp…"   5 minutes ago       Up 5 minutes                    0.0.0.0:8080->80/tcp                control-panel_frontend_1
48ee29caee6a        control-panel_mongodb         "docker-entrypoint.s…"   5 minutes ago       Up 5 minutes                    0.0.0.0:27017->27017/tcp            control-panel_mongodb_1
5514f5e97a65        mysql/mysql-server:5.7        "/entrypoint.sh mysq…"   2 days ago          Up 2 days (healthy)             0.0.0.0:3306->3306/tcp, 33060/tcp   mysql-migration

客户给我这个:enter image description here

它甚至都没有机会对凭据进行身份验证。而且我看到端口在本地和Docker容器中打开。

我尝试过: sudo lsof -i tcp:27017

它得到:

com.docke 31591 jgonz   23u  IPv4 0xaa557204f5a42733      0t0  TCP *:27017 (LISTEN)
com.docke 31591 jgonz   26u  IPv6 0xaa557204e73407f3      0t0  TCP localhost:27017 (LISTEN)

我不确定我的配置中缺少什么。另外,在docker-compose的文件夹级别,我有一个.env文件,其中包含所有环境变量。通过遵循本文,我的mongodb Dockerfile运行了两个脚本: http://blog.bejanalex.com/2017/03/running-mongodb-in-a-docker-container-with-authentication/

0 个答案:

没有答案