user706838
user706838

Reputation: 5380

How to alter the mount point of PostgreSQL through Docker?

I want to spin-up a docker for postgres:latest but let the data be stored on the host. This is how I do it right now but doesn't seem to work. Any ideas?

docker run --name name1 -e POSTGRES_PASSWORD=PASSWORD1 -e POSTGRES_USER=USER1 -e PGDATA=/my/local/path/postgresql -e POSTGRES_DB=DB1 -d -P postgres:latest

Upvotes: 0

Views: 458

Answers (1)

Matt
Matt

Reputation: 74670

You need to mount the host directory as a data volume first with -v host_path:contiainer_path:mode.

docker run \
  --name name1 \
  -v /my/local/path/postgresql:/data \
  -e POSTGRES_PASSWORD=PASSWORD1 \
  -e POSTGRES_USER=USER1 \
  -e PGDATA=/data \
  -e POSTGRES_DB=DB1 \
  -d -P postgres:latest

The path should exist in the container image.

Upvotes: 3

Related Questions