| 用途 | 结构化挂载声明 |
|---|---|
| 语法 | --mount type=…,source=…,target=…[,readonly] |
| 差异 | bind 源不存在时直接报错 |
示例
示例
docker run -d --mount type=volume,source=pgdata,target=/var/lib/postgresql/data postgres:16-alpine
docker run -d --mount type=bind,source=/srv/www,target=/usr/share/nginx/html,readonly nginx
docker run --rm --mount type=tmpfs,target=/tmp,tmpfs-size=64m alpine df -h /tmp脚本与 Compose 迁移场景更适合 --mount:路径解析与错误提示都比 -v 明确。