Skip to content

体积

一句话解释

体积是 storage mechanism 那个 lets 容器 persist 数据偶数当 容器是 停止 or recreated.

用大白话说

Containers are ephemeral — when a container is destroyed, all data inside it is lost. Volumes solve this problem by providing persistent storage that exists outside the container's lifecycle.

In Docker, a volume is a directory on the host machine that is mounted into the container. When the container writes to the volume, the data is actually stored on the host. When the container is recreated, the volume is re-mounted and the data is still there.

In Kubernetes, volumes are more powerful. There are many types: emptyDir (temporary, shared between containers in a Pod), hostPath (host directory), persistentVolume (long-lived storage), and cloud-specific volumes like EBS, Azure Disk, etc.

示例

bash
# Docker: mount a volume
docker run -v /host/data:/container/data myapp

# Kubernetes: persistent volume claim
# (defined in YAML, mounted in Pod spec)

Docker command mounts /host/数据从 host 到容器 at /容器/数据. 数据 persists 偶数之后容器是 移除.

工作原理

  1. You define a volume (in Docker run command or Kubernetes YAML).
  2. The volume is created on the host or a storage backend.
  3. The container/Pod mounts the volume at a specified path.
  4. Data written to the volume persists beyond the container's life.

常见混淆

  • 容易混淆的对象: Bind Mount

    关键区别: Docker 体积是 managed 通过 Docker and 存储 in Docker-managed 位置; bind mount uses 特定 host path directly.

相关术语

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表