剛剛用docker-compose部署elk的時候,沒有起來,查看日志的時候,發現在數據卷掛載的時候,報錯權限不足。
由於日志不在了,這里就直接貼出解決辦法。
問題原因及解決辦法
原因是CentOS7中的安全模塊selinux把權限禁掉了,至少有以下三種方式解決掛載的目錄沒有權限的問題:
1.在運行容器的時候,給容器加特權,及加上 --privileged=true 參數:
docker run -i -t -v /soft:/soft --privileged=true 686672a1d0cc /bin/bash
注:這種適合docker run
2.臨時關閉selinux:
setenforce 0
用這種解決了問題。
3.添加selinux規則,改變要掛載的目錄的安全性文本
# 更改安全性文本的格式如下
chcon [-R] [-t type] [-u user] [-r role] 文件或者目錄 選頃不參數: -R :連同該目錄下癿次目錄也同時修改; -t :后面接安全性本文的類型字段!例如 httpd_sys_content_t ; -u :后面接身份識別,例如 system_u; -r :后面街覘色,例如 system_r [root@localhost Desktop]# chcon --help Usage: chcon [OPTION]... CONTEXT FILE... or: chcon [OPTION]... [-u USER] [-r ROLE] [-l RANGE] [-t TYPE] FILE... or: chcon [OPTION]... --reference=RFILE FILE... Change the SELinux security context of each FILE to CONTEXT. With --reference, change the security context of each FILE to that of RFILE. Mandatory arguments to long options are mandatory for short options too. --dereference affect the referent of each symbolic link (this is the default), rather than the symbolic link itself -h, --no-dereference affect symbolic links instead of any referenced file -u, --user=USER set user USER in the target security context -r, --role=ROLE set role ROLE in the target security context -t, --type=TYPE set type TYPE in the target security context -l, --range=RANGE set range RANGE in the target security context --no-preserve-root do not treat '/' specially (the default) --preserve-root fail to operate recursively on '/' --reference=RFILE use RFILE's security context rather than specifying a CONTEXT value -R, --recursive operate on files and directories recursively -v, --verbose output a diagnostic for every file processed The following options modify how a hierarchy is traversed when the -R option is also specified. If more than one is specified, only the final one takes effect. -H if a command line argument is a symbolic link to a directory, traverse it -L traverse every symbolic link to a directory encountered -P do not traverse any symbolic links (default) --help display this help and exit --version output version information and exit GNU coreutils online help: <http://www.gnu.org/software/coreutils/> For complete documentation, run: info coreutils 'chcon invocation'
在主機中修改/soft目錄的安全性文檔
[root@localhost Desktop]# chcon -Rt svirt_sandbox_file_t /soft [root@ba471da26d07 soft]# ll total 384264 -rw-r--r--. 1 root root 212046774 Aug 8 10:01 hadoop-2.7.2.tar.gz -rw-r--r--. 1 root root 181435897 Aug 8 09:23 jdk-8u102-linux-x64.tar.gz 在docker中就可以正常訪問該目錄下的相關資源了。
原文鏈接:https://blog.csdn.net/rznice/article/details/52170085