mongo-express / mongo-express-docker

a dockerized mongo-express for viewing mongoDB in the browser
MIT License
203 stars 93 forks source link

Could not connect to database using connectionString: mongodb://mongo:27017" #67

Open jrujano-zz opened 3 years ago

jrujano-zz commented 3 years ago

Trying in different ways I have not been able to connect to my mongodb through mongo-express

Selección_136

Selección_137

thomas-hofmann-dci commented 3 years ago

same result withing the following environment: Latest (as of now) mongo-express and mongo (4.4-bionic and latest) docker-images.

sample "docker-compose.yml":

services:

  mongo:
    image: mongo #:4.4-bionic

    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: example

    # optionally make it available to the outside
    ports:
      - "27017:27017" 

  mongo-express:
    image: mongo-express
    ports:
      - 8081:8081
    environment:
      ME_CONFIG_MONGODB_ADMINUSERNAME: root
      ME_CONFIG_MONGODB_ADMINPASSWORD: example
JafarAkhondali commented 3 years ago

@thomas-hofmann-dci Try connecting using ME_CONFIG_MONGODB_URL

mtwinux commented 3 years ago

Same error here. Tried a few config. Event the docker-compose.yml on the main page of mongo (https://hub.docker.com/_/mongo) leads to the same error.

The only way to get this working is to set the 0.54.0 tag version :

version: "3.7" services: mongodb: container_name: mongo-dev image: mongo environment:

And i will not use ME_CONFIG_MONGODB_URL as it is not documented on the main page of the mongo-express dockerhub and therefore it should work without it.

JafarAkhondali commented 3 years ago

@mtwinux The page on dockerhub is outdated, as of version 1, you should use ME_CONFIG_MONGODB_URL, if for some reason you don't want to, you'll have to use version 0.X

gBusato commented 3 years ago

This configuration should work:

version: '3.1'

services:

  mongo:
    image: mongo
    restart: always
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: example

  mongo-express:
    image: mongo-express
    restart: always
    ports:
      - 8081:8081
    environment:
      ME_CONFIG_MONGODB_URL: "mongodb://root:example@mongo:27017/"
      ME_CONFIG_MONGODB_ADMINUSERNAME: root
      ME_CONFIG_MONGODB_ADMINPASSWORD: example
ebukaodini commented 3 years ago

Screenshot from 2021-10-18 09-10-25

Looking at this error message, it says "failed to connect to server [mongo:27017] on first connect". So I added the restart option to the mongo-express service and it worked for me.

mongo-express:
    image: mongo-express
    restart: always
    ...

I hope that this reply is helpful

m-ocean-it commented 3 years ago

Solution for latest mongo-express (on Mac OS)

Digests of used images:

In my case, I had to change the host name in the ME_CONFIG_MONGODB_URL variable to kubernetes.docker.internal: "mongodb://admin:password@kubernetes.docker.internal:27017". I fetched that from the /private/etc/hosts file on my Mac OS. (The .yaml file is below.)

Using restart for mongo-express is also mandatory.

Until finding the described solution, I tried restarting the Docker daemon and rebooting my machine; both actions did nothing.

Here's the working .yaml file:

version: '3'
services:
    mongodb:
        image: mongo
        ports:
            - 27017:27017
        environment:
            - MONGO_INITDB_ROOT_USERNAME=admin
            - MONGO_INITDB_ROOT_PASSWORD=password
    mongo-express:
        image: mongo-express
        restart: always
        ports:
            - 8080:8081
        environment:
            - ME_CONFIG_MONGO_DB_ADMINUSERNAME=admin
            - ME_CONFIG_MONGO_DB_ADMINPASSWORD=password
            - ME_CONFIG_MONGO_DB_SERVER=mongodb
            - ME_CONFIG_MONGODB_URL="mongodb://admin:password@kubernetes.docker.internal:27017"
wbqtac commented 2 years ago

mongo-express:0.54.0

This solution works with me. As the end of March, 2022, mongo-express:latest version is [1.0.0-alpha.4]. mongo:latest version 5.0.6-focal

following docker-compose works with me. Many thanks to @mtwinux

How can I share code here? The format looks bad.

version: '3.1'

services:

mongo: image: mongo restart: always environment: MONGO_INITDB_ROOT_USERNAME: root MONGO_INITDB_ROOT_PASSWORD: example

mongo-express: image: mongo-express:0.54.0 restart: always ports:

psoder commented 2 years ago

How can I share code here? The format looks bad.

@wbqtac to format code in blocks wrap it in ` (backticks).

If you only want to include something inline, like this, the syntax is `<text goes here>`

For full code blocks use:

```<language goes here (e.g. java or cpp)>
<code goes here>
For example:
println("Hello World!")
will display,
```kotlin
println("Hello World!")

See GitHub's formatting guide for more details.

johurul000 commented 2 years ago

As of today using an image of mongo-express version 0.54.0 Works for me.

The is my .yaml file

version: '3'
services: 
  mongodb:
    image:  mongo:4.4.17-focal
    container_name: mongodb
    ports:
      - 27017:27017
    environment:
      - MONGO_INITDB_ROOT_USERNAME=admin
      - MONGO_INITDB_ROOT_PASSWORD=password
  mongo-express:
    image: mongo-express:0.54.0
    restart: always
    container_name: mongo-express
    ports:
      - 8081:8081
    environment:
      - ME_CONFIG_MONGODB_ADMINUSERNAME=admin
      - ME_CONFIG_MONGODB_ADMINPASSWORD=password
      - ME_CONFIG_MONGODB_SERVER=mongodb
siddharthans2000 commented 1 year ago

As of today using an image of mongo-express version 0.54.0 Works for me.

The is my .yaml file

version: '3'
services: 
  mongodb:
    image:  mongo:4.4.17-focal
    container_name: mongodb
    ports:
      - 27017:27017
    environment:
      - MONGO_INITDB_ROOT_USERNAME=admin
      - MONGO_INITDB_ROOT_PASSWORD=password
  mongo-express:
    image: mongo-express:0.54.0
    restart: always
    container_name: mongo-express
    ports:
      - 8081:8081
    environment:
      - ME_CONFIG_MONGODB_ADMINUSERNAME=admin
      - ME_CONFIG_MONGODB_ADMINPASSWORD=password
      - ME_CONFIG_MONGODB_SERVER=mongodb

Yeah thanks this works for me too, but still haven't able to figure it out why it is showing error with the latest packages

Nischal2015 commented 1 year ago

This is what worked for me

version: '3'
services:
  mongodb:
    image: mongo
    container_name: mongodb
    ports:
      - 27017:27017
    environment:
      - MONGO_INITDB_ROOT_USERNAME=admin
      - MONGO_INITDB_ROOT_PASSWORD=password

  mongo-express:
    image: mongo-express
    container_name: mongo-express
    ports:
      - 8081:8081
    depends_on:
      - mongodb
    restart: always
    environment:
      - ME_CONFIG_MONGODB_ADMINUSERNAME=admin
      - ME_CONFIG_MONGODB_ADMINPASSWORD=password
      - ME_CONFIG_MONGODB_SERVER=mongodb
TESLAOPUnix commented 1 year ago

I also have same issue with this currently trying using cli now I guess compose is the only option

maddes-b commented 9 months ago

The documentation on Docker Hub is outdated: see https://github.com/mongo-express/mongo-express/issues/1414 and #106 After 1.0 the usage of ME_CONFIG_MONGODB_SERVER has been changed, normally you will use ME_CONFIG_MONGODB_URL now, e.g. with mongodb://admin:password@mongodb:27017

Make sure to read the README here on GitHub regarding the tag you are using.

ademaldemir commented 6 months ago

add this env param to mongo-express ME_CONFIG_BASICAUTH: false It worked for me! 🚀

InWamos commented 3 weeks ago

The following worked for me on Debian 12

But despite the config, it still creates a default admin user with the following credentials: admin pass Docker logs for this: mongo_ui | basicAuth credentials are "admin:pass", it is recommended you change this in your config.js!

services:

  mongo:
    image: mongo:6
    restart: always
    container_name: mongo
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: example
    volumes:
      - ./db_data/:/data/db/
      - /etc/timezone:/etc/timezone:ro
      #   remain this only if you want a mongoDB to be accesible from your LAN
    ports:
      - 27017:27017

  mongo-express:
    image: mongo-express
    restart: always
    container_name: mongo_ui
    ports:
      - 8081:8081
    environment:
      ME_CONFIG_MONGODB_ENABLE_ADMIN: true
      ME_CONFIG_MONGODB_ADMINUSERNAME: root
      ME_CONFIG_MONGODB_ADMINPASSWORD: example
      ME_CONFIG_MONGODB_URL: mongodb://root:example@mongo:27017/

Run with: sudo docker compose up -d from a directory with the .yml file