Initialize data on dockerized mongo

后端 未结 5 609
無奈伤痛
無奈伤痛 2020-12-08 05:35

I\'m running a dockerized mongo container.

I\'d like to create a mongo image with some initialized data.

Any ideas?

5条回答
  •  不知归路
    2020-12-08 05:52

    with the latest release of mongo docker , something like this works for me.

    FROM mongo
    COPY dump /home/dump
    COPY mongo_restore.sh /docker-entrypoint-initdb.d/
    

    the mongo restore script looks like this.

    #!/bin/bash
    # Restore from dump
    mongorestore --drop --gzip --db "" /home/dump
    

    and you could build the image normally.

    docker build -t  .
    

提交回复
热议问题