简体   繁体   English

`docker-compose.yml` 中的根级空 object 是什么意思?

[英]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.我认为最重要的是拥有自己的生命周期,因为它允许您将数据作为工件进行版本、备份或操作,独立于容器实例或容器映像。

See also:也可以看看:

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

相关问题 {} 在 docker-compose.yml 的服务部分是什么意思 - What does {} means in services section of docker-compose.yml 为什么在 docker-compose.yml 中使用空白/空卷允许持久性但使用相对路径失败(例如 jenkins gui 不可用)? - Why does using a blank/empty volume in docker-compose.yml allow persistence but using a relative path fails (eg jenkins gui unavailable)? 如何在 Docker 中检查卷是否存在且不为空,并根据此运行不同的 docker-compose.yml? - How to check in Docker whether a volume exists and is not empty and run different docker-compose.yml depending on this? 我的docker-compose.yml有什么问题? - What is wrong with my docker-compose.yml? 什么是 docker-compose.yml 文件? - What is a docker-compose.yml file? 这个 docker-compose.yml 文件有什么问题 - What is wrong with this docker-compose.yml file 在 docker-compose.yml 卷中为 Docker Swarm 安装 OpenMediaVault NFS - Mount OpenMediaVault NFS in docker-compose.yml volume for Docker Swarm 在部分中和服务下声明docker-compose.yml卷有什么区别? - What's the difference between declaring in docker-compose.yml volume as section and under a service? 如何使用docker-compose.yml文件命名卷? - How to name a volume using a docker-compose.yml file? docker-compose.yml在以点(。)开头的文档上使用卷 - docker-compose.yml use volume on documents starting with dot (.)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM