Single Volume for Multiple Postgresql DB containers

I have two Postgres databases and I want to sync data between them.

So far I have these two containers, exactly the same with different posts and different names.

docker container run --name='p1' -d -p 5435:5432 -v /tmp/dbs/test/:/var/lib/postgresql/data postgres
docker container run --name='p2' -d -p 5436:5432 -v /tmp/dbs/test/:/var/lib/postgresql/data postgres  

The problem happens when something changed.

If I change something in p1 like insert a row, then I can’t see it in p2.

But if I kill, and run containers again, then I can see the inserted data in both of them.

Why this is happening?

Is there a way to sync data between themes?

Never mount the same data into different database containers. It is true even without containers. Never use the same data for different database servers! This is not the way to create a redundant database service. Each database engine has its own proper way for data replication. In case of postgresql

But I just did a queick search so you may find a better guide.