无法读取绑定分区的数据

在遵循docker文档的示例时,无法读取数据。 有可能,我的dockerconfiguration有问题吗?

按照这个创build一个容器: https : //docs.docker.com/engine/tutorials/dockervolumes/#mount-a-host-file-as-a-data-volume

docker run --rm -it -v ~/.bash_history:/root/.bash_history ubuntu /bin/bash

当我尝试从容器中看到历史logging时,我得到一个“权限被拒绝的错误”:

 root@81076476fa68:/# history 1 ls -la ~/ 2 history root@81076476fa68:/# cat ~/.bash_history cat: /root/.bash_history: Permission denied 

.bash_history文件的所有权是否有问题?

 root@81076476fa68:/# ls -la ~/ total 60 drwx------ 2 root root 4096 Mar 8 21:14 . drwxr-xr-x 35 root root 4096 Mar 8 21:14 .. -rw------- 1 nobody nogroup 42996 Mar 8 21:06 .bash_history -rw-r--r-- 1 root root 3106 Oct 22 2015 .bashrc -rw-r--r-- 1 root root 148 Aug 17 2015 .profile 

4.4和4.10内核都给出了相同的结果。

我在Linux Mint 18.1上。 以下是一些系统信息:

 $ uname -a Linux a 4.4.0-65-generic #86-Ubuntu SMP Thu Feb 23 17:49:58 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux $ docker --version Docker version 17.03.0-ce, build 3a232c8 $ docker info Containers: 39 Running: 1 Paused: 0 Stopped: 38 Images: 269 Server Version: 17.03.0-ce Storage Driver: aufs Root Dir: /var/lib/docker/296608.296608/aufs Backing Filesystem: extfs Dirs: 395 Dirperm1 Supported: true Logging Driver: json-file Cgroup Driver: cgroupfs Plugins: Volume: local Network: bridge host macvlan null overlay Swarm: inactive Runtimes: runc Default Runtime: runc Init Binary: docker-init containerd version: 977c511eda0925a723debdc94d09459af49d082a runc version: a01dafd48bc1c7cc12bdb01206f9fea7dd6feb70 init version: 949e6fa Security Options: apparmor seccomp Profile: default userns Kernel Version: 4.4.0-65-generic Operating System: Linux Mint 18.1 OSType: linux Architecture: x86_64 CPUs: 8 Total Memory: 15.55 GiB Name: a-dell ID: IEJP:6N34:GFBS:VIOM:HDBW:NVOF:BH3E:HZFO:3SOE:AACN:VZCV:FSWZ Docker Root Dir: /var/lib/docker/296608.296608 Debug Mode (client): false Debug Mode (server): false Registry: https://index.docker.io/v1/ WARNING: No swap limit support Experimental: false Insecure Registries: 127.0.0.0/8 Live Restore Enabled: false 

UPDATE

我发现问题出在文件访问权限/属性上。 当我改变我的.bash_history的属性以允许所有人阅读,docker容器可以访问它。 有没有办法与我运行的容器共享我的文件访问权限?

 $ docker --version Docker version 17.03.0-ce, build 3a232c8 

看来你运行的是Docker的边缘版本,而不是稳定的(边缘是17.x,最新的稳定是1.13我认为)。

在Ubuntu和Docker 1.13的框中运行相同的例子,一切都按预期工作。

所以我的build议是使用稳定的版本,除非你真的需要使用边缘。