Reputation: 658
I have a docker container that was running postgresql db but it was accidentally deleted by my Apache Mesos Marathon
.
Is there any way I can restore the container or at least, get the database files?
Thanks
Upvotes: 14
Views: 63484
Reputation: 1708
The accepted answer is correct, however I would like to add the specific steps to restore an app (in my case it was a PostgreSQL database) via its docker volume.
I am using Docker version 18.09.0, build 4d60db4 in CentOS.
/var/lib/docker/volumes/
._data
folder that contains the application files for that container. Find the specific volume you wish to restore and save its container ID somewhere to remember it in the next steps.docker volume ls
to make sure that container ID is listed as volume. That will be our volume_name
to restore.docker run -d --name postgres -p 5432:5432 postgres
.docker inspect postgres
Mounts
section and check the Destination
. In my case it was /lib/postgresql/data
.docker run -d --name postgres -p 5432:5432 --mount source=volume_name,target=/var/lib/postgresql/data postgres
Upvotes: 15
Reputation: 46500
If it's just stopped, rather than removed, you should be able to find it under docker ps -a
and just run docker start CONTAINER
.
Unless the database was removed with docker rm -v CONTAINER
, the database files are probably still in a directory somewhere under /var/lib/docker/vfs/dir/
, but you may have a hard time figuring out which one. If you do manage to figure out the correct directory, you should be able to restore the db by just mounting the directory into a new database instance.
Upvotes: 11