Home > Mobile >  Recover data for Postgress in Docker after docker-compose down
Recover data for Postgress in Docker after docker-compose down

Time:01-21

i have a problem. First i needed to install Redis on my project, so i went to file docker-compose.xml , done some chenges in file and after that i use command docker-compose down , and docker-compose up. As result i don`t see data in my database postgres(( i looked all volumes in docker, and one of them has date 3 days ago, can i take this volume,i think it can be restore some data for me, but i dont know how to do it.

vadym@vadym-K56CM:~$ docker volume ls
DRIVER    VOLUME NAME
local     7fd43398fb9942381adf3a866c9408ee3cbe24e5d33ed4e4374bfcea77405ed7
local     7fe3a58893af638ca2a7ac8389cc8794cd1ab56a807ce4b8ee47ed67b8d67b90
local     562d3c85b32450f0f8bfc73420438a72f7b6651317f7efa43cd38e6d9a7de887
local     e698eb5804793b624159ae4e2eef01e15b43bd937e139aa586b0ec35b209c376
local     linkup_redis
local     vscode

i need to restore volume with name 562d3c85b32450f0f8bfc73420438a72f7b6651317f7efa43cd38e6d9a7de887.

My container

vadym@vadym-K56CM:~$ docker ps
CONTAINER ID   IMAGE            COMMAND                  CREATED       STATUS       PORTS                         NAMES
01f8d5219a62   redis            "docker-entrypoint.s…"   3 hours ago   Up 3 hours   0.0.0.0:6379->6379/tcp        redis
22eb79cb829e   dpage/pgadmin4   "/entrypoint.sh"         3 hours ago   Up 3 hours   0.0.0.0:80->80/tcp, 443/tcp   postgres_gui
4e98b4c62cc4   postgres:14.4    "docker-entrypoint.s…"   3 hours ago   Up 3 hours   0.0.0.0:5432->5432/tcp        postgres_container

Thanks!

CodePudding user response:

You should be able to mount the volume to a new container and then copy data from it. E.g. here is how to create a minimalistic container, mount the specified volume as read-only (see :ro at the end) and copy data from that volume into directory backup:

docker run -it -v <volumeID>:/mnt/myvolume:ro --name mycontainer alpine

docker cp mycontainer:/mnt/myvolume .\backup\
  • Related