Need some advice docting MongoDB

I play with MongoDB and Docker, and at this moment I am trying to create a useful image for myself to use it at work. I created the following Dockerfile:

FROM mongo:2.6
MAINTAINER Reynier Perez <reynierpm@gmail.com>
VOLUME /data/db /data/configdb
CMD ["mongod"]
EXPOSE 27017

And I added it to my docker-compose.ymlfile:

version: '2'
services:
    ### PHP/Apache Container
    php-apache:
        container_name: "php55-dev"
        image: reynierpm/php55-dev
        ports:
            - "80:80"
        environment:
            PHP_ERROR_REPORTING: 'E_ALL & ~E_DEPRECATED & ~E_NOTICE'
        volumes:
            - ~/mmi:/var/www
            - ~/data:/data
        links:
            - mongodb
    ### MongoDB Container
    mongodb:
        container_name: "mongodb"
        build: ./mongo
        environment:
            MONGODB_USER: "xxxx"
            MONGODB_DATABASE: "xxxx"
            MONGODB_PASS: "xxxx"
        ports:
            - "27017:27017"
        volumes:
            - ~/data/mongo:/data/db

I have some questions regarding this setup I made:

  • Do I need VOLUME /data/db /data/configdbto Dockerfileor is this enough to have this line ~/data/mongo:/data/configdbin docker-compose.yml?
  • I assume (and I took it from here ) that as soon as I build a Mongo image, I will create a database and give full permissions to the user with a password, how about environment variables? I'm not wrong? (I did not find anything useful here )
  • mongo ( JSON) , mongo? , mongorestore, ? script ? ? ?
+4
1

VOLUME/data/db/data/configdb Docker , ~/data/mongo:/data/configdb docker-compose.yml?

VOLUME , . VOLUME " " Docker ( ), .

( ), , , , ? ? ( )

MONGO_USER, MONGO_DATABASE MONGO_PASS mongo mongod.

mongo :

  • MONGO_INITDB_ROOT_USERNAME
  • MONGO_INITDB_ROOT_PASSWORD
  • MONGO_INITDB_DATABASE

mongo ( JSON) , mongo? , mongorestore, ? script ? ? ?

, . , Docker VOLUME , . , , , .

mongorestore . RUN. script, .

Mongo mongo, , .

+3

Source: https://habr.com/ru/post/1659558/


All Articles