You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

跨分区创建Docker卷及容器跨分区挂载卷的可行性咨询

Answer

Absolutely, but you'll need to combine Docker volumes with a host-side bind mount to make this work—let me break this down clearly, since your requirement has a specific twist (keeping data on partition A while having a "pointer" to it on partition B).

First, let's clarify core concepts to avoid confusion:

  • Docker Volumes: Managed directly by Docker, these live in your Docker root directory (which you've set to partition A, so volume data stays on A—exactly what you want).
  • Bind Mounts: These map a host directory directly to a container path. Using a bind mount for partition B's directory directly would write data to B, which you don't want.

Here's the step-by-step solution:

  1. Create a Docker Volume (stored on partition A)
    First, make a Docker-managed volume that will live on partition A (since your Docker root is configured there):

    docker volume create my_app_volume
    
  2. Locate the volume's actual storage path
    Find where Docker stores this volume on your host (it will be on partition A):

    docker volume inspect my_app_volume
    

    Look for the Mountpoint field in the output—this is the absolute path on partition A (e.g., /var/lib/docker/volumes/my_app_volume/_data).

  3. Bind-mount the volume's path to partition B's directory
    Create a "pointer" on partition B that links to the volume's actual data on A. Use the mount --bind command to map the volume's mountpoint to a directory on B:

    # Replace /mnt/B/my_volume_access with your desired directory on partition B
    # Replace the first path with the Mountpoint from step 2
    mount --bind /var/lib/docker/volumes/my_app_volume/_data /mnt/B/my_volume_access
    

    This makes the volume's data accessible via partition B's directory, but the actual data never leaves partition A.

  4. Make the bind mount persistent (optional but recommended)
    To keep this mapping after system reboots, add an entry to /etc/fstab:

    /var/lib/docker/volumes/my_app_volume/_data /mnt/B/my_volume_access none bind 0 0
    
  5. Use the volume in your container
    When running your container (which lives on partition A), mount the Docker volume to the desired path inside the container:

    docker run -d -v my_app_volume:/path/inside/container your_container_image
    

Key Notes:

  • No data is stored on partition B—the directory on B is just a mounted link to the volume's data on A.
  • If you ever need to access the volume's data from the host, you can use either the original mountpoint on A or the linked directory on B—both point to the same data.
  • Avoid using a direct bind mount from B to the container, as that would force data to write to B (which you explicitly don't want).

内容的提问来源于stack exchange,提问作者agentn

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:44:10