简体   繁体   中英

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM