Howto persist MongoDB - data of a running Docker container in a new image?

后端 未结 2 602
我寻月下人不归
我寻月下人不归 2021-02-04 14:08

i have a running Mongo DB Container called xyz from offical Mongo Image. i created the container with docker run -d -p 21707:21707 mongo In this container i create

2条回答
  •  悲哀的现实
    2021-02-04 15:05

    I used docker commit and created a new image, pushed it on the docker hub. If i pull the image on a other system and create a new container from this image, there are no data like in my origin container xyz.

    The mongo docker image writes its data into a volume. As a result, those data won't be saved to a new docker image created with docker commit. docker export won't produce your data for the same reason.

    how could i reach to migrate this "xyz" running container with my sample data in a new image/container?

    What you want is either:

    • create a new container re-using the first container's volume → see --volumes-from
    • save the first container's volume data into a directory on your docker host, and create a new container mounting this directory into the container → the docker run -v option

    Also, this SO question might help you figure out volumes.

提交回复
热议问题