docker日誌掛載的問題

關鍵是本地服務器沒有寫入的權限 

關鍵看這裏吧(Permission denied), 一直沒有看正方,以爲是配置日誌文件 找不到有問題,下面是部分異常

10:35:09,498 |-ERROR in ch.qos.logback.core.rolling.RollingFileAppender[FILE] - openFile(null,true) call failed. java.io.FileNotFoundException: logs/bandwidth.log.2019-04-25.log (Permission denied)
        at java.io.FileNotFoundException: logs/bandwidth.log.2019-04-25.log (Permission denied)
        at      at java.io.FileOutputStream.open0(Native Method)
        at      at java.io.FileOutputStream.open(FileOutputStream.java:270)
        at      at java.io.FileOutputStream.<init>(FileOutputStream.java:213)
        at      at ch.qos.logback.core.recovery.ResilientFileOutputStream.<init>(ResilientFileOutputStream.java:26)
        at      at ch.qos.logback.core.FileAppender.openFile(FileAppender.java:204)
        at      at ch.qos.logback.core.FileAppender.start(FileAppender.java:127)
        at      at ch.qos.logback.core.rolling.RollingFileAppender.start(RollingFileAppender.java:100)
        at      at ch.qos.logback.core.joran.action.AppenderAction.end(AppenderAction.java:90)
        at      at ch.qos.logback.core.joran.spi.Interpreter.callEndAction(Interpreter.java:309)
        at      at ch.qos.logback.core.joran.spi.Interpreter.endElement(Interpreter.java:193)

嘗試好多遍,才真正看懂原因也是從網上看到的一點啓發,希望大家也能注意到,我用如下命令完美解決

docker run   -it --privileged=true    -v /dockerlogs:/app/logs   -d -p 5080:5080  82edb4bbc79b

掛載宿主機已存在目錄後,在容器內對其進行操作,報“Permission denied”

可通過兩種方式解決:

1> 關閉selinux。

臨時關閉:# setenforce 0

永久關閉:修改/etc/sysconfig/selinux文件,將SELINUX的值設置爲disabled。

2> 以特權方式啓動容器 

指定--privileged參數

如:# docker run -it --privileged=true -v /test:/softlogs  

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章