我想到以下两个方法:
使用-v参数同步data文件
执行时,没找到data文件,查了postgresql.conf
,说在/var/lib/postgresql/9.5/main
但是看了文件大小很小,而我的数据很大。
而且我猜测是否可以这样做,直接同步data文件达到数据同步。
通过
-p 5432
,使Docker在增删改查时都采用宿主机数据库?
执行时 -p
参数时,报错5432
已被占用, 因为我的其他程序在访问数据库。
我该怎么做,让Docker的数据和主机数据实时同步。
It is recommended to read Docker’s official documentation or introductory tutorial.
There is no concept of synchronization between the container and the host.
Can’t two database instances use the same data file? I’ve never seen a database that can do this....
I don’t understand the second way....
PS: If you really want to [synchronize the database of the host and docker. You can form a cluster... This is the way I can think of...
Method 2:
If you want to use the application in Docker on the host
postgres
, you can use the public network to directly access the host’s public IP and the corresponding port