简体   繁体   中英

How to use Robo3T to connect mongodb server running as a docker container

I have a mongodb running as a docker container which created by docker-compose. Here is my docker-compose.yml:

verion:'3.7'
services:
    mongo_env:
        image: mongo:4.2.1-bionic
        ports: 
            - "27017:27017"
        volumes: 
            - $PWD/DBVOL/mongo/data:/data/db:rw
        environment: 
            MONGO_INITDB_ROOT_USERNAME: <rootuser>
            MONGO_INITDB_ROOT_PASSWORD: <mypassword>
            MONGO_INITDB_DATABASE: <mydatabase>

I want to connect mongodb from outside using Robo 3T,But It always tell me that 'Failed to load database'.Here is my Robo 3T config: 在此处输入图片说明

Please Help me It's emergency!

Are your sure it started successfull? Your Docker Compose has a typo in "version:3.7". correct version:

version: '3.7'
services:
mongo_env:
    image: mongo:4.2.1-bionic
    ports: 
        - "27017:27017"
    volumes: 
        - $PWD/DBVOL/mongo/data:/data/db:rw
    environment: 
        MONGO_INITDB_ROOT_USERNAME: <rootuser>
        MONGO_INITDB_ROOT_PASSWORD: <mypassword>
        MONGO_INITDB_DATABASE: <mydatabase>

Please check after starting if the container is running with

docker ps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM