[英]What does a root level empty object for volume means in `docker-compose.yml`?
I am trying to learn volume in docker-compose.yml
, and I came across this code from this example:我正在尝试在docker-compose.yml
中学习音量,我从这个例子中遇到了这个代码:
https://docs.docker.com/compose/wordpress/ https://docs.docker.com/compose/wordpress/
version: "3.9"
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
# Make db_data persistant
db_data: {}
For the global volume db_data
, can I understand it as mySQL data(from /var/lib/mysql) will be saved in an object called db_data
?对于全局卷db_data
,我可以将其理解为mySQL 数据(来自 /var/lib/mysql)将保存在名为db_data
的 object 中吗? If this understanding is wrong, what is the correct meaning for this code?如果这种理解是错误的,那么这段代码的正确含义是什么?
Please find more on the official Docker documentation请在官方Docker 文档中找到更多信息
Volumes are the preferred mechanism for persisting data generated by and used by Docker containers.卷是保存由 Docker 容器生成和使用的数据的首选机制。 While bind mounts are dependent on the directory structure and OS of the host machine, volumes are completely managed by Docker.虽然绑定挂载取决于主机的目录结构和操作系统,但卷完全由 Docker 管理。 Volumes have several advantages over bind mounts:与绑定挂载相比,卷有几个优点:
You can imagine db_data
as a hard drive.您可以将db_data
想象成一个硬盘驱动器。 Yes, like a physical hard disk that you can move from left to right, you can backup, it has its own lifecycle.是的,就像一个可以从左到右移动的物理硬盘,可以备份,它有自己的生命周期。
I consider has its own lifecycle the most important thing, because it allows you to Version, backup or manipulate that data as an artifact , independent of the container instance or container image.我认为最重要的是拥有自己的生命周期,因为它允许您将数据作为工件进行版本、备份或操作,独立于容器实例或容器映像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.