docker system_error ai_generated true

docker: Error response from daemon: error while mounting volume '/host/path': permission denied

ID: docker/volume-mount-permission-denied-on-host

Also available as: JSON · Markdown · 中文
88%Fix Rate
86%Confidence
1Evidence
2023-11-20First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Docker 23.0.6 active
Docker 24.0.2 active

Root Cause

Docker daemon lacks read/write permission on the host directory specified in a bind mount.

generic

中文

Docker 守护进程对绑定挂载中指定的主机目录缺乏读/写权限。

Official Documentation

https://docs.docker.com/storage/bind-mounts/

Workarounds

  1. 90% success Run 'sudo chown -R root:root /host/path' or adjust permissions to 755 to ensure Docker daemon (running as root) can access the directory.
    Run 'sudo chown -R root:root /host/path' or adjust permissions to 755 to ensure Docker daemon (running as root) can access the directory.
  2. 85% success If using SELinux, run 'sudo chcon -Rt svirt_sandbox_file_t /host/path' to set proper context for Docker volumes.
    If using SELinux, run 'sudo chcon -Rt svirt_sandbox_file_t /host/path' to set proper context for Docker volumes.

中文步骤

  1. 运行 'sudo chown -R root:root /host/path' 或将权限调整为 755,以确保 Docker 守护进程(以 root 身份运行)可以访问该目录。
  2. 如果使用 SELinux,运行 'sudo chcon -Rt svirt_sandbox_file_t /host/path' 为 Docker 卷设置正确的上下文。

Dead Ends

Common approaches that don't work:

  1. 40% fail

    Running container with --privileged flag ignores the underlying permission issue and may cause security risks.

  2. 80% fail

    Changing volume path to a different directory without fixing host permissions repeats the error.