2015-03-31 129 views
0

當試圖將卷映射到tomcat容器中的主機時,我在CentOS 7上遇到了一個問題。這發生在公共tomcat圖像以及我創建的圖像上(基於centos而不是debian)。CentOS 7上的Docker卷

實例化一個容器如下就會成功: 搬運工運行 - 它-d tomcat的:8

實例化一個容器如下會成功,但隨着日誌中的錯誤和日誌不會被寫入到主機: 搬運工運行 - 它-d -v在/ usr /本地/ Tomcat的:在/ usr /本地/ Tomcat的Tomcat的:8

[[email protected] tomcat]$ dkr run -it -d -v 

/usr/local/tomcat:/usr/local/tomcat tomcat:8 
34075701b1436f83a24212170b4d2113ae698df244c449203b1c9af9814485c9 
[[email protected] tomcat]$ dkr ps 
CONTAINER ID  IMAGE    COMMAND    CREATED    STATUS    PORTS    NAMES 
34075701b143  tomcat:8   "catalina.sh run" 5 seconds ago  Up 4 seconds  8080/tcp   sharp_einstein 
[[email protected] tomcat]$ dkr logs sharp_einstein 
Using CATALINA_BASE: /usr/local/tomcat 
Using CATALINA_HOME: /usr/local/tomcat 
Using CATALINA_TMPDIR: /usr/local/tomcat/temp 
Using JRE_HOME:  /usr 
Using CLASSPATH:  /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar 
java.util.logging.ErrorManager: 4 
java.io.FileNotFoundException: /usr/local/tomcat/logs/catalina.2015-03-31.log (Permission denied) 

... 

31-Mar-2015 15:32:04.088 SEVERE [Catalina-startStop-1] org.apache.catalina.startup.HostConfig.start Unable to create directory for deployment: /usr/local/tomcat/conf/Catalina/localhost 
31-Mar-2015 15:32:04.097 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/ROOT 
31-Mar-2015 15:32:04.468 WARNING [localhost-startStop-1] org.apache.catalina.core.StandardContext.postWorkDirectory Failed to create work directory [/usr/local/tomcat/work/Catalina/localhost/ROOT] for context [] 
31-Mar-2015 15:32:05.966 SEVERE [localhost-startStop-1] org.apache.jasper.EmbeddedServletOptions.<init> The scratchDir you specified: /usr/local/tomcat/work/Catalina/localhost/ROOT is unusable. 
31-Mar-2015 15:32:06.042 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/ROOT has finished in 1,929 ms 
31-Mar-2015 15:32:06.043 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/docs 
31-Mar-2015 15:32:06.093 WARNING [localhost-startStop-1] org.apache.catalina.core.StandardContext.postWorkDirectory Failed to create work directory [/usr/local/tomcat/work/Catalina/localhost/docs] for context [/docs] 
31-Mar-2015 15:32:06.216 SEVERE [localhost-startStop-1] org.apache.jasper.EmbeddedServletOptions.<init> The scratchDir you specified: /usr/local/tomcat/work/Catalina/localhost/docs is unusable. 
31-Mar-2015 15:32:06.219 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory /usr/local/tomcat/webapps/docs has finished in 176 ms 
31-Mar-2015 15:32:06.220 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory /usr/local/tomcat/webapps/examples 
31-Mar-2015 15:32:06.272 WARNING [localhost-startStop-1] org.apache.catalina.core.StandardContext.postWorkDirectory Failed to create work directory [/usr/local/tomcat/work/Catalina/localhost/examples] for context [/examples] 
31-Mar-2015 15:32:07.952 SEVERE [localhost-startStop-1] org.apache.jasper.EmbeddedServletOptions.<init> The scratchDir you specified: /usr/local/tomcat/work/Catalina/localhost/examples is unusable. 
[[email protected] tomcat]$ 

Exec'ing到容器,並試圖也寫失敗。

[[email protected] tomcat]$ dkr ps 
CONTAINER ID  IMAGE    COMMAND    CREATED    STATUS    PORTS    NAMES 
34075701b143  tomcat:8   "catalina.sh run" 5 minutes ago  Up 5 minutes  8080/tcp   sharp_einstein 
[[email protected] tomcat]$ dkr exec -it sharp_einstein /bin/bash 
[email protected]:/usr/local/tomcat# ls -l 
total 96 
-rw-rw-r--. 1 root root 56977 Jan 23 11:59 LICENSE 
-rw-rw-r--. 1 root root 1397 Jan 23 11:59 NOTICE 
-rw-rw-r--. 1 root root 6779 Jan 23 11:59 RELEASE-NOTES 
-rw-rw-r--. 1 root root 16204 Jan 23 11:59 RUNNING.txt 
drwxrwxr-x. 2 root root 4096 Mar 31 12:14 bin 
drwxrwxr-x. 2 root root 4096 Jan 23 11:59 conf 
drwxrwxr-x. 2 root root 4096 Mar 31 12:14 lib 
drwxrwxr-x. 2 root root  6 Jan 23 11:56 logs 
drwxrwxr-x. 2 root root 29 Mar 31 12:14 temp 
drwxrwxr-x. 7 root root 76 Jan 23 11:57 webapps 
drwxrwxr-x. 2 root root  6 Jan 23 11:56 work 
[email protected]:/usr/local/tomcat# cd logs 
[email protected]:/usr/local/tomcat/logs# echo "test" > test.log 
bash: test.log: Permission denied 

我已經在CentOS創建的PostgreSQL容器的實例和成功的映射和使用量,通過創建一個數據庫,停止實例,然後重新運行容器驗證。

[[email protected] ~]$ uname --all 
Linux eagle2 3.10.0-123.20.1.el7.x86_64 #1 SMP Thu Jan 29 18:05:33 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux 
[[email protected] ~]$ 

dkr是docker的別名,我創建了一個docker組並將自己添加到該組中,以消除對sudo的需求。

卷映射似乎在ubuntu上正常工作。在CentOS上,我嘗試了兩個軟件包版本(如下所示),並將它更新到1.5。

[[email protected] ~]$ dkr --version 
Docker version 1.3.2, build 39fa2fa/1.3.2 
[[email protected] ~]$ 

如何使卷在CentOS上正常工作?

回答

0

我認爲你的卷 working :-)你有權限問題。我經常遇到這種情況,主機和容器之間的用戶標識映射。在您的主機上,如果您查看/ usr/local/tomcat(ls -ld),您將看到所有者,組和權限。你可能有類似於0755的東西(所有者讀/寫/執行,組讀/執行,世界讀/執行)。你可以很容易地測試這個理論,簡單記住/ usr/local/tomcat/logs的當前設置,然後做:

chmod 777 /usr/local/tomcat/logs 

泊塢窗主機(不是容器),然後運行您的容器上測試,否認權限應蒸發

這是不是一個很好的修復,雖然我不。不知道社區對docker的用戶標識映射有什麼看法,你可以做的一件事是找出你的主機上的用戶和組,然後當你創建你的映像時(或者在運行時)創建一個用戶同一個ID d在容器中具有相同ID的組。然後在容器中使用該用戶運行你的tomcat服務。

+0

格雷格,感謝 - 我認爲你是在正確的我有一個權限問題,而不是體積問題。也就是說,您建議的修復方法無效。 '$ ll/usr/local/tomcat drwxrwxrwx。2 root root 6 Apr 6 09:23日誌 $ dkr運行-it -d -v/usr/local/tomcat/logs:/ usr/local/tomcat/logs tomcat:8 5661653ac2 $ dkr logs 5661653ac2 使用CATALINA_BASE :/ usr/local/tomcat ... java.io.FileNotFoundException:/usr/local/tomcat/logs/catalina.2015-04-06.log(Permission denied)' 我想知道是否有問題與filesytem:xfs? – 2015-04-06 13:49:29

+0

我在主機文件系統和容器ID之間的用戶標識映射和許可方面遇到了很多麻煩。我想這就是你在這裏所做的。很難閱讀註釋輸出...對不起...在容器中,你可以觸摸/usr/local/tomcat/logs/catalina.2015-04-06.log'?該文件是否已經存在權限錯誤?或者,是Java創建它與錯誤的許可? (umask設置錯誤)? – Greg 2015-04-06 15:26:19

+0

對不起,在評論區塊中格式化很困難。 在日誌文件夾中沒有任何東西存在,我可以在那裏觸摸或創建一個文件。在容器中什麼都不存在,我也無法創建任何東西。觸摸嘗試返回'權限被拒絕'。該容器中顯示的該文件夾(日誌)的權限是777,所有者和組都是root。 Umask是0022. – 2015-04-08 13:16:54

0

這是由於SELinux。

您必須附上正確類型的託管目錄:

host$ chcon -Rt svirt_sandbox_file_t /usr/local/tomcat