Mongorestore in a Dockerfile

前端 未结 5 825
借酒劲吻你
借酒劲吻你 2021-02-05 07:10

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

5条回答
  •  清歌不尽
    2021-02-05 08:01

    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
    

提交回复
热议问题