MongoDB
 sql >> Teknologi Basis Data >  >> NoSQL >> MongoDB

Mongorestore di Dockerfile

Dengan bantuan dari jawaban ini , jawaban Marc Young, dan referensi Dockerfile saya dapat membuatnya berfungsi.

Dockerfile

FROM mongo

COPY dump /home/dump
COPY mongo.sh /home/mongo.sh
RUN chmod 777 /home/mongo.sh

CMD /home/mongo.sh

mongo.sh

#!/bin/bash

# Initialize a mongo data folder and logfile
mkdir -p /data/db
touch /var/log/mongodb.log
chmod 777 /var/log/mongodb.log

# Start mongodb with logging
# --logpath    Without this mongod will output all log information to the standard output.
# --logappend  Ensure mongod appends new entries to the end of the logfile. We create it first so that the below tail always finds something
/entrypoint.sh mongod --logpath /var/log/mongodb.log --logappend &

# Wait until mongo logs that it's ready (or timeout after 60s)
COUNTER=0
grep -q 'waiting for connections on port' /var/log/mongodb.log
while [[ $? -ne 0 && $COUNTER -lt 60 ]] ; do
    sleep 2
    let COUNTER+=2
    echo "Waiting for mongo to initialize... ($COUNTER seconds so far)"
    grep -q 'waiting for connections on port' /var/log/mongodb.log
done

# Restore from dump
mongorestore --drop /home/dump

# Keep container running
tail -f /dev/null


  1. Redis
  2.   
  3. MongoDB
  4.   
  5. Memcached
  6.   
  7. HBase
  8.   
  9. CouchDB
  1. Mungkinkah membandingkan string tanggal di mongodb?

  2. skema mongo (penyematan vs referensi)

  3. Indeks Senyawa MongoDB - Apakah urutan pengurutan penting?

  4. Kueri di Bidang Hash Mongoid

  5. Mongo $addToSet sebuah Array