无法访问共享数据卷

Not able to access shared data volume

我一直在尝试在我的主机和 docker 容器之间共享数据。我正在使用此命令挂载数据卷:

sudo docker run -it -v /home/peeyush/Docker/docker/:/opt/test/:rw ubuntu /bin/bash

现在,当我 运行 docker 并尝试访问 /opt/test/ 时,它说我没有权限。但是我已经指定了读写权限,而且我是root。这是输出:

root@d61b3bfe0aab:/# ls /opt/test/
ls: cannot open directory /opt/test/: Permission denied

知道我做错了什么吗?

更新:这是 ls -al /home/peeyush/Docker/docker:

的输出
[peeyush@localhost docker]$ ls -al /home/peeyush/Docker/docker/
total 308
drwxrwxr-x. 29 peeyush peeyush  4096 Feb 24 14:14 .
drwxrwxr-x.  5 peeyush peeyush  4096 Feb 23 15:38 ..
drwxrwxr-x.  5 peeyush peeyush  4096 Feb 23 11:53 api
-rw-rw-r--.  1 peeyush peeyush 28898 Feb 23 11:53 AUTHORS
drwxrwxr-x.  4 peeyush peeyush  4096 Feb 23 11:53 builder
drwxrwxr-x.  2 peeyush peeyush  4096 Feb 23 11:53 builtins
drwxrwxr-x.  3 peeyush peeyush  4096 Feb 23 13:36 bundles
-rw-rw-r--.  1 peeyush peeyush 61942 Feb 23 11:53 CHANGELOG.md
drwxrwxr-x. 11 peeyush peeyush  4096 Feb 23 11:53 contrib
-rw-rw-r--.  1 peeyush peeyush 13305 Feb 23 11:53 CONTRIBUTING.md
drwxrwxr-x.  5 peeyush peeyush  4096 Feb 23 11:53 daemon
drwxrwxr-x.  2 peeyush peeyush  4096 Feb 23 11:53 docker
-rw-rw-r--.  1 peeyush peeyush  5423 Feb 24 14:14 Dockerfile
-rw-rw-r--.  1 peeyush peeyush    16 Feb 23 11:53 .dockerignore
drwxrwxr-x.  2 peeyush peeyush  4096 Feb 23 11:53 dockerinit
drwxrwxr-x.  5 peeyush peeyush  4096 Feb 23 11:53 docs
drwxrwxr-x.  2 peeyush peeyush  4096 Feb 23 11:53 engine
drwxrwxr-x.  2 peeyush peeyush  4096 Feb 23 11:53 events
drwxrwxr-x.  8 peeyush peeyush  4096 Feb 24 14:14 .git
-rw-rw-r--.  1 peeyush peeyush   489 Feb 23 11:53 .gitignore
drwxrwxr-x.  2 peeyush peeyush  4096 Feb 23 11:53 graph
lrwxrwxrwx.  1 peeyush peeyush     7 Feb 23 11:53 hack -> project
drwxrwxr-x.  3 peeyush peeyush  4096 Feb 23 11:53 image
drwxrwxr-x.  3 peeyush peeyush  4096 Feb 23 11:53 integration
drwxrwxr-x.  2 peeyush peeyush  4096 Feb 23 11:53 integration-cli
-rw-rw-r--.  1 peeyush peeyush 10763 Feb 23 11:53 LICENSE
drwxrwxr-x.  2 peeyush peeyush  4096 Feb 23 11:53 links
-rw-rw-r--.  1 peeyush peeyush  7171 Feb 23 11:53 .mailmap
-rw-rw-r--.  1 peeyush peeyush 18599 Feb 23 11:53 MAINTAINERS
-rw-rw-r--.  1 peeyush peeyush  3400 Feb 23 11:53 Makefile
drwxrwxr-x.  2 peeyush peeyush  4096 Feb 23 11:53 nat
-rw-rw-r--.  1 peeyush peeyush   638 Feb 23 11:53 NOTICE
drwxrwxr-x.  2 peeyush peeyush  4096 Feb 23 11:53 opts
drwxrwxr-x. 39 peeyush peeyush  4096 Feb 23 11:53 pkg
drwxrwxr-x.  3 peeyush peeyush  4096 Feb 23 11:53 project
-rw-rw-r--.  1 peeyush peeyush 10624 Feb 23 11:53 README.md
drwxrwxr-x.  3 peeyush peeyush  4096 Feb 23 11:53 registry
drwxrwxr-x.  2 peeyush peeyush  4096 Feb 23 11:53 runconfig
drwxrwxr-x.  2 peeyush peeyush  4096 Feb 23 11:53 trust
drwxrwxr-x.  2 peeyush peeyush  4096 Feb 23 11:53 utils
drwxrwxr-x.  3 peeyush peeyush  4096 Feb 23 11:53 vendor
-rw-rw-r--.  1 peeyush peeyush    10 Feb 23 11:53 VERSION
drwxrwxr-x.  2 peeyush peeyush  4096 Feb 23 11:53 volumes

和 ls -al /opt/:

root@d61b3bfe0aab:/# ls -al /opt/
total 12
drwxr-xr-x.  3 root root 4096 Feb 25 06:22 .
drwxr-xr-x. 21 root root 4096 Feb 25 06:58 ..
drwxrwxr-x. 29 1000 1000 4096 Feb 24 08:44 test

谢谢。

有兴趣看看它是否可以在目录路径上没有尾随 '/' 的情况下工作,因为我从未使用过它们,也从未遇到过这个问题。

sudo docker 运行 -it -v /home/peeyush/Docker/docker:/opt/test ubuntu /bin/bash

使用带有 SELinux 的发行版?您可以尝试将其设置为被动 (setenforce 0) 或在 -v 命令末尾尝试 :Z/:z,例如 (/home/peeyush/Docker/docker:/opt/test:Z)