[Docker] ls: cannot open directory .: Permission denied 解決方式
今天要將container 裡面的檔案路徑mapping到實體主機的檔案路徑 docker run -it -v /home/user1/storage:/storage centos /bin/bash 時,在container裡的storage下ls卻出現 ls: cannot open directory .: Permission denied,以下為解決方法:
[root@centos-minion share]# id -Z
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[root@centos-minion share]# ls -ldZ /home/share
drwxr-xr-x. root root unconfined_u:object_r:home_root_t:s0 /home/share
The container:
[root@4ccce73bed9d share]# id -Z
id: --context (-Z) works only on an SELinux-enabled kernel
[root@4ccce73bed9d share]# ls -ldZ /home/share
drwxr-xr-x. root root unconfined_u:object_r:home_root_t:s0 /home/share
原因就出在SELinux,可以輸入
參考來源:https://github.com/moby/moby/issues/14175
環境:Linux
解決方式:
在host和container分別查看id -Z:[root@centos-minion share]# id -Z
unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[root@centos-minion share]# ls -ldZ /home/share
drwxr-xr-x. root root unconfined_u:object_r:home_root_t:s0 /home/share
The container:
[root@4ccce73bed9d share]# id -Z
id: --context (-Z) works only on an SELinux-enabled kernel
[root@4ccce73bed9d share]# ls -ldZ /home/share
drwxr-xr-x. root root unconfined_u:object_r:home_root_t:s0 /home/share
原因就出在SELinux,可以輸入
docker run -it -v /home/share:/home/share:z或
docker run -it -v /home/share:/home/share:Z就解決囉!
參考來源:https://github.com/moby/moby/issues/14175
留言
張貼留言