时间:2021-07-01 10:21:17 帮助过:140人阅读
3、mongo-Dockerfile
1 FROM mongo:3.4 2 ENV WORKSPACE /usr/local/work 3 ENV AUTO_RUN_DIR /docker-entrypoint-initdb.d 4 ENV INSTALL_MONGO_SHELL setup.sh 5 RUN mkdir -p $WORKSPACE 6 COPY ./data/*.json $WORKSPACE/ 7 COPY ./$INSTALL_MONGO_SHELL $AUTO_RUN_DIR/ 8 RUN chmod a+x $AUTO_RUN_DIR/$INSTALL_MONGO_SHELL
4、setup.sh
1 #!/bin/bash 2 mongo <<EOF 3 use admin; 4 db.createUser({ user: ‘root‘, pwd: ‘123456‘, roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] }); 5 6 use new_db; 7 db.createCollection("collection1"); 8 db.createCollection("collection2"); 9 EOF 10 11 mongoimport --db new_db --collection collection1 --file $WORKSPACE/xxx1.json 12 mongoimport --db new_db --collection collection2 --file $WORKSPACE/xxx2.json
5、在docker-compose.yml目录下执行
1 docker-compose up -d
over。
docker-compose 构建mongodb并导入基础数据示例
标签:alt set ash 文件目录 tab doc roo docke shell