我的数据库已创建但内部没有集合:/
这是使用命令 - >的日志。 docker-compose logs:
Attaching to dockernode_dbseed_1, dockernode_app_1, dockernode_db_1
dbseed_1 | 2015-12-23T16:21:04.228+0000 connected to: db:27017
dbseed_1 | 2015-12-23T16:21:04.286+0000 imported 2 documents
db_1 | 2015-12-23T16:06:37.127+0000 I CONTROL [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=18f02be6b100
db_1 | 2015-12-23T16:06:37.128+0000 I CONTROL [initandlisten] db version v3.2.0
db_1 | 2015-12-23T16:06:37.128+0000 I CONTROL [initandlisten] git
db_1 | 2015-12-23T16:06:37.135+0000 I CONTROL [initandlisten] target_arch: x86_64
app_1 | warn: --minUptime not set. Defaulting to: 1000ms
app_1 | warn: --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
app_1 | info: Forever processing file: /hp_app/hp-climatology-api/index.js
app_1 | warn: --minUptime not set. Defaulting to: 1000ms
app_1 | warn: --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
db_1 | 2015-12-23T16:06:37.152+0000 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=1G,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0)
/ dbseed / Dockerfile
FROM mongo
COPY climat.json climat.json
RUN adduser --gecos '' --disabled-password mongod \
&& mkdir -p /mongo_app \
&& chown -R mongod /mongo_app
USER mongod
WORKDIR /mongo_app
COPY run_mongo.sh run_mongo.sh
USER root
RUN chown -R mongod:mongod /mongo_app
CMD ["/mongo_app/run_mongo.sh"]
/dbseed/run_mongo.sh:
#!/bin/sh
mongoimport --host db --db hpApiDev --port 27017 --collection coll --type json --file /files/climat.json --jsonArray;
sleep 10;
这是/dbseed/climat.json
[
{
"name": "Joe Smith",
"email": "jsmith@gmail.com",
"age": 40,
"admin": false
},
{
"name": "Jen Ford",
"email": "jford@gmail.com",
"age": 45,
"admin": true
}
]
这是docker-compose.yml
db:
image: mongo
ports:
- 27017:27017
dbseed:
build: ./dbseed
links:
- db
volumes:
- ./dbseed:/files
app:
build: .
links:
- db:db
ports:
- 8080:8080
提前感谢您的帮助:)