i want create docker image starts mongo server , automatically restores previous mongodump
on startup.
here dockerfile image:
mongo copy dump /home/dump cmd mongorestore /home/dump
when run this, run error:
failed: error connecting db server: no reachable servers
is there way mongorestore
command run through docker?
with this answer, marc young's answer, , dockerfile reference able working.
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 mongo data folder , logfile mkdir -p /data/db touch /var/log/mongodb.log chmod 777 /var/log/mongodb.log # start mongodb logging # --logpath without mongod output log information standard output. # --logappend ensure mongod appends new entries end of logfile. create first below tail finds /entrypoint.sh mongod --logpath /var/log/mongodb.log --logappend & # wait until mongo logs it's ready (or timeout after 60s) counter=0 grep -q 'waiting connections on port' /var/log/mongodb.log while [[ $? -ne 0 && $counter -lt 60 ]] ; sleep 2 let counter+=2 echo "waiting mongo initialize... ($counter seconds far)" grep -q 'waiting connections on port' /var/log/mongodb.log done # restore dump mongorestore --drop /home/dump # keep container running tail -f /dev/null
Comments
Post a Comment