Home  >  Q&A  >  body text

Postgresql 宿主机如何与Docker同步数据?

我想到以下两个方法:

使用-v参数同步data文件

执行时,没找到data文件,查了postgresql.conf,说在/var/lib/postgresql/9.5/main但是看了文件大小很小,而我的数据很大。

而且我猜测是否可以这样做,直接同步data文件达到数据同步。

通过-p 5432,使Docker在增删改查时都采用宿主机数据库?

执行时 -p参数时,报错5432已被占用, 因为我的其他程序在访问数据库。

我该怎么做,让Docker的数据和主机数据实时同步。

大家讲道理大家讲道理2705 days ago635

reply all(3)I'll reply

  • 怪我咯

    怪我咯2017-04-27 09:03:44

    It is recommended to read Docker’s official documentation or introductory tutorial.
    There is no concept of synchronization between the container and the host.

    reply
    0
  • 世界只因有你

    世界只因有你2017-04-27 09:03:44

    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...

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-04-27 09:03:44

    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

    reply
    0
  • Cancelreply