简体   繁体   中英

How can I recover data from deleted MongoDB docker container

I have used MongoDB container to run MongoDB Service and use this service to store data.

By mistake, I have deleted this container. The MongoDB container does not exist in the system now.

Would it be still possible for me to recover MongoDB data on my local system?

Step 1 - Locate the data storage

This depends on many factors, like the specific configuration of the image that was used to create the container. Usually, in a local environment a MongoDB container would use a Docker volume for data storage. It could very well be that the volume is still intact on the machine.

To check for existing volumes on the machine, run docker volume ls . The resulting list may look something like this:

DRIVER              VOLUME NAME
local               6d72f04429db8907b35715e8e189f60cfcf4901a4938e2c7af1d135b2430623e
local               35bed434757398055f75d0b5cf6242eb0a55095c3822f61705b4b237cada980d
local               50d72cc4d1dc93af1d70a43a322119e5dfb44e9c8d52853b631e49962ee9532f
local               d31828b239d8f2f5c4979b16df9a6bbf73919e1b34d448284db2f1aa73059844
local               docker-dev_mongodb-data
local               docker_mongodb-data
local               blah-api_mongodb-data

The specific naming of the available volumes would naturally differ and depend on past and present containers on the specific machine.

Step 2 - Create a new container that uses the data storage

If you locate the relevant volume, you can create a new MongoDB container that uses the existing volume. If the MongoDB version of the new container is compatible with the previous container's, the data should be available and accessible as before.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM