How to run MongoDB and Mongo-express with docker-compose?

前端 未结 8 2098
情话喂你
情话喂你 2021-02-14 07:10

I try to run MongoDB and Mongo-express by Docker-compose. I use following config:

version: \'3\'

services:
    mongo:
        image: mongo
        environment:
         


        
8条回答
  •  [愿得一人]
    2021-02-14 08:12

    it works in my mac. If you delete docker-compose containers and rebuild, maybe it will work. I added my files. Only i changed mongo-express port.

    .env

    MONGO_ROOT_USER=devroot
    MONGO_ROOT_PASSWORD=devroot
    MONGOEXPRESS_LOGIN=dev
    MONGOEXPRESS_PASSWORD=dev
    

    docker-compose.yml

    version: '3'
    
    services:
        mongo:
            image: mongo
            environment:
                - MONGO_INITDB_ROOT_USERNAME=${MONGO_ROOT_USER}
                - MONGO_INITDB_ROOT_PASSWORD=${MONGO_ROOT_PASSWORD}
                - MONGO_INITDB_DATABASE=project
        mongo-express:
            image: mongo-express
            environment:
                - ME_CONFIG_MONGODB_SERVER=mongo
                - ME_CONFIG_MONGODB_PORT=27017
                - ME_CONFIG_MONGODB_ENABLE_ADMIN=false
                - ME_CONFIG_MONGODB_AUTH_DATABASE=admin
                - ME_CONFIG_MONGODB_AUTH_USERNAME=${MONGO_ROOT_USER}
                - ME_CONFIG_MONGODB_AUTH_PASSWORD=${MONGO_ROOT_PASSWORD}
                - ME_CONFIG_BASICAUTH_USERNAME=${MONGOEXPRESS_LOGIN}
                - ME_CONFIG_BASICAUTH_PASSWORD=${MONGOEXPRESS_PASSWORD}
            depends_on:
                - mongo
            ports:
              - "8888:8081"
    

    Docker Version

    Client:
     Version:           18.06.0-ce
     API version:       1.38
     Go version:        go1.10.3
     Git commit:        0ffa825
     Built:             Wed Jul 18 19:05:26 2018
     OS/Arch:           darwin/amd64
     Experimental:      false
    
    Server:
     Engine:
      Version:          18.06.0-ce
      API version:      1.38 (minimum version 1.12)
      Go version:       go1.10.3
      Git commit:       0ffa825
      Built:            Wed Jul 18 19:13:46 2018
      OS/Arch:          linux/amd64
      Experimental:     true
    

提交回复
热议问题