Reputation: 5380
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
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