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
If you have a backup of your Docker Container stored as a Tar File in your local machine or pushed it on the Docker Hub account, you can restore that Tar File back into a Docker Image, create a Container and use it.
Go to /var/lib/docker/volumes/ . In this folder, there are folders which are named as container IDs. Each container ID folder has a _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 uses storage drivers to store image layers, and to store data in the writable layer of a container. The container's writable layer does not persist after the container is deleted, but is suitable for storing ephemeral data that is generated at runtime.
Restore your dataUse docker pull to restore images you pushed to Docker Hub. If you backed up your images to a local tar file, use docker image load -i images. tar to restore previously saved images. Re-create your containers if needed, using docker run , or Docker Compose.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With