[英]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, 我可否知道,
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 :-)
:)如果不存在,则必须创建它:-)
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.