简体   繁体   English

使用非外部卷是在dockerized postgres中持久保存数据的好方法

[英]Is using non external volume a good way to persist data in dockerized postgres

After reading 看完之后

How to persist data in a dockerized postgres database using volumes 如何使用卷将数据持久化在dockerized postgres数据库中

I know mount a volume to local host folder, is a good way to prevent data loss, in case fatal happens in docker process. 我知道将卷安装到本地主机文件夹中,是防止数据丢失的好方法,以防在docker进程中发生致命事故。

I'm using Windows as host and Linux based docker image. 我正在使用Windows作为主机和基于Linux的Docker映像。 Windows is having problem to mount postgres data (Linux based docker image) to Windows host directory - Mount Postgres data to Windows host directory Windows在将postgres数据(基于Linux的docker映像) 挂载到Windows主机目录时遇到问题-将Postgres数据挂载到Windows主机目录

Later, I discover another technique 后来我发现了另一种技术

  postgres:
    build:
      context: ./postgres
      dockerfile: Dockerfile
    restart: always
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data

volumes:
  postgres_data: {}

I can use a non external volume (I have no idea what is that yet) 我可以使用非外部卷(我不知道那是什么)

After implement such, I try to perform 实施后,我尝试执行

docker-compose down
docker-compose up

The data is still there. 数据仍然在那里。

May I know, 我可否知道,

  1. Is this still a good way to persist data in dockerized postgres? 这仍然是在dockerized postgres中持久保存数据的好方法吗?
  2. Where exactly data is being stored? 确切的数据存储在哪里? Is it some hidden directory in host machine? 它是主机中的某个隐藏目录吗?
  1. Is this still a good way to persist data in dockerized postgres? 这仍然是在dockerized postgres中持久保存数据的好方法吗? no but olso yes ....postgres is DB so data should be externalized to avoid data-loss in case of connection failure to the container etc... 否,但是olso是.... postgres是数据库,因此应将数据外部化,以避免在与容器的连接失败等情况下数据丢失。

But a good practice would be to have 2 DB 1 on containers 1 on host or in 2 containers (then with data inside containers) in master/slave mode synchro to have high availability for container maintenance for example but this is high availability only not backup ! 但是一个好的做法是在主机/从属模式下在主机上的容器1上或在2个容器(然后容器内有数据)上的2个DB 1处于同步状态,以具有例如用于容器维护的高可用性,但这仅是高可用性而不是备份! :) if it doesn't exist you have to create it of course :-) :)如果不存在,则必须创建它:-)

  1. Where exactly data is being stored? 确切的数据存储在哪里? Is it some hidden directory in host machine? 它是主机中的某个隐藏目录吗?

No it is where you share the /var/lib/postgres so in your example in a directory called postgres_data on host 不,它是共享/ var / lib / postgres的位置,因此在您的示例中位于主机上名为postgres_data的目录中

(use full path is a good practice & then you saw/guess by yourself where it was define in your file) :) (使用完整路径是一种很好的做法,然后您可以自己查看/猜测文件中定义的位置) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用卷将数据保存在 dockerized postgres 数据库中 - How to persist data in a dockerized postgres database using volumes 如何使用相同的 DATABASE_HOST 从 dockerized django 和非 dockerized django 将 django 应用程序连接到 dockerized postgres db - How to connect a django app to a dockerized postgres db, both from a dockerized django and non-dockerized django using same DATABASE_HOST 如何使用postgres docker镜像保留数据? - How to persist data using postgres docker image? 将 pytest 与 dockerized Postgres 数据库一起使用 - Using pytest with a dockerized Postgres database 使用docker swarm模式时如何在卷上保留数据? - How to persist data on a volume when using docker swarm mode? Docker卷不保留数据 - Docker volume does not persist data 使用SQLAlchemy将Pandas数据框转换为Dockerized Postgres - Pandas dataframe to Dockerized Postgres using SQLAlchemy 如何使用postgres数据库,Docker和Kubernetes来保存数据? - How to persist data using a postgres database, Docker, and Kubernetes? 以非阻塞方式使用滑线插入Postgres - Insert into postgres using slick in a non blocking way 更新服务时Postgres AWS EBS卷不持久 - Postgres AWS EBS volume doesn't persist when updating service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM