I am using postgres docker: image 9.4. I need to know how to back up and restore only a container with volumes.
Created volume container:
docker run -v /var/lib/postgresql/data --name dbdata postgres:9.4 /bin/true
Using the volume
docker run --name=postgres --volumes-from=dbdata -d -p 6432:5432 postgres:9.4
Reserve container
docker run --volumes-from dbdata -v $(pwd):/backup postgres:9.4 tar cvf /backup/backup.tar /var/lib/postgresql/data
Recover volume in a new container
docker run --name=dbdata-new --volumes-from dbdata -v $(pwd):/backup ubuntu:14.04 /bin/sh -c 'cd /var/lib/postgresql/data && tar xvf /backup/backup.tar'
Use in a new volume when creating a new postgres container:
docker run --name=postgres-new --volumes-from=dbdata-new -d -p 7532:5432 postgres:9.4
Problem: I get the following error in the logs when starting a new container.
initdb: the directory "/ var / lib / postgresql / data" exists, but is not empty If you want to create a new database system, delete or delete the directory "/ var / lib / postgresql / data" or run initdb with an argument other than " / var / lib / postgresql / data "
Not sure what I'm doing wrong. Can someone please indicate where I am making a mistake.
docker postgresql
unnik
source share