DEV Community

Herbz
Herbz

Posted on

Docker + Flask + Vue + Nginx + MongoDB- deployment and development in one package (3)

Chapter 7: Initialize MongoDB

  • Now that we have a running backend and frontend, the next step is to get the database running so we can handle data better.

  • In our docker-compose.yml add following:

    mongodb:
        image: mongo:4.2.5-bionic
        container_name:  mongodb
        restart: always
        environment:
            - MONGO_INITDB_ROOT_USERNAME=root
            - MONGO_INITDB_ROOT_PASSWORD=example
        volumes:
            - './database:/data/db'
        ports:
            - "27017:27017"
            - "27018:27018"
            - "27019:27019"
        expose:
            - 27017
            - 27018
            - 27019

    mongo-express:
        image: mongo-express
        restart: always
        environment:
            # mongodb authentication
            - ME_CONFIG_MONGODB_ADMINUSERNAME=root
            - ME_CONFIG_MONGODB_ADMINPASSWORD=example
            # mongodb URI
            - ME_CONFIG_MONGODB_SERVER=mongodb
            - ME_CONFIG_MONGODB_PORT=27017
            # web login username and password
            - ME_CONFIG_BASICAUTH_USERNAME=mongo
            - ME_CONFIG_BASICAUTH_PASSWORD=express
        ports:
            - 8081:8081
  • This setup allows us to have mongodb and a nice web UI mongo-express running. For additional security, we have set password for our db, and we have also set a web login BASICAUTH for our mongo-express service.

  • Spin this up with docker-compose up --build

  • In the browser, we can access to our database with localhost:8081 via mongo-express.

Top comments (0)