I want to create a Docker image that starts a mongo server and automatically restores from a previous mongodump
on startup.
Here is my Dockerfile for
You probably don't want to use this for production but it does what you need:
== Dockerfile ==
FROM mongo:3
COPY restore.sh /restore.sh
COPY ./mongodump /dump/
ENTRYPOINT /restore.sh
then
== restore.sh ==
#!/usr/bin/env bash
# Execute restore in the background after 5s
# https://docs.docker.com/engine/reference/run/#detached--d
sleep 5 && mongorestore /dump &
# Keep mongod in the foreground, otherwise the container will stop
docker-entrypoint.sh mongod