0

I created container with command

sudo docker run --rm \
  --name selectel-pgdocker_pgdata \
  -p 5432:5432 \
  -e POSTGRES_USER=selectel \
  -e POSTGRES_PASSWORD=selectel \
  -e POSTGRES_DB=selectel \
  -e PGDATA=/var/lib/postgresql/data/pgdata \
  -d \
  -v $HOME/docker/volumes/postgres:/var/lib/postgresql/data \
  postgres

But after, I used command

psql -h 127.0.0.1 -U selectel -d selectel

and start creating databases and tables in psql. But my /var/lib/postgresql/data/pgdata still doesn't exist. If I create the directory manually, it is still empty. What should I do? I want to save my data in the main filesystem, not inside Docker.

David Maze
  • 130,717
  • 29
  • 175
  • 215
Excentricitet
  • 143
  • 1
  • 1
  • 6

1 Answers1

0

The volume you are creating is defined by $HOME/docker/volumes/postgres:/var/lib/postgresql/data, therefore you should check the contents of your $HOME/docker/volumes/postgres directory, as it is the source directory mapped to your machine.

Iker
  • 16
  • 1
  • 5
  • so what aim of pgdata? What difference between pgdata and volume? – Excentricitet Nov 20 '21 at 12:13
  • and i need to save my postgresql data out of container (on server) – Excentricitet Nov 20 '21 at 12:15
  • The internal representation of the DB is saved within dbdata, that is from postgres. The concept "volume" is a docker abstraction of the physical hard drives, in order to make the container save files into a directory inside the container which is actually a directory in your machine. – Iker Nov 20 '21 at 12:22
  • If your configuration is correct and the container is running, the created database will be in that directory. You can check the container logs with docker logs selectel-pgdocker_pgdata – Iker Nov 20 '21 at 12:24