这是我的docker-compose文件:
version: '3' services: mongo: hostname: mongo container_name: search_mongo image: mongo:latest volumes: - ./docker/local/persist/mongo:/data/db - ./docker/mongo:/opt/mongo ports: - "8884:27017" - "8885:27018" entrypoint: /opt/mongo/entrypoint_mongo.sh agent: build: . image: myapp_search:compose depends_on: - mongo
这是我的entrypoint_mongo.sh
#!/bin/bash mongod --port 27018 --replSet rs0 --fork --syslog --smallfiles mongo --port 27018 --eval "rs.initiate({_id : 'rs0', members : [{_id : 0, host : 'mongo:27018'}]})" mongo --port 27018 --eval "while(true) {if (rs.status().ok) break;sleep(1000)};"
我面临的问题是:mongo容器正在成功执行所有步骤,但是退出时的状态为0。
mongo_1 | about to fork child process, waiting until server is ready for connections. mongo_1 | forked process: 7 mongo_1 | child process started successfully, parent exiting mongo_1 | MongoDB shell version v3.4.10 mongo_1 | connecting to: mongodb://127.0.0.1:27018/ mongo_1 | MongoDB server version: 3.4.10 mongo_1 | { "ok" : 1 } mongo_1 | MongoDB shell version v3.4.10 mongo_1 | connecting to: mongodb://127.0.0.1:27018/ mongo_1 | MongoDB server version: 3.4.10 search_mongo exited with code 0
您的启动脚本不应初始化或监视副本集。这些应该是手动任务。
您应该记住:
我强烈建议您进行三处更改: