我正在尝试代表tomcat用户在docker容器中运行Tomcat。 这是Dockerfile:
FROM centos:latest
...
RUN groupadd -g743 tomcat
RUN useradd -u734 -M -s /bin/nologin -g tomcat -d /opt/tomcat tomcat
...
RUN chown -R tomcat:tomcat /opt/tomcat/
RUN chmod o+rwx /opt/tomcat
...
USER tomcat
CMD ["/opt/tomcat/bin/catalina.sh", "run"]
我在tomcat用户下以交互模式运行容器:
bash-4.2$ whoami
tomcat
但由于以下原因,Tomcat未能启动:
21-May-2016 21:55:34.262 SEVERE [Catalina-startStop-1] org.apache.catalina.valves.AccessLogValve.open Failed to open access log file [/opt/tomcat/logs/localhost_access_log.2016-05-21.txt]
java.io.FileNotFoundException: /opt/tomcat/logs/localhost_access_log.2016-05-21.txt (Permission denied) at java.io.FileOutputStream.open0(Native Method)
tomcat用户拥有/ opt / tomcat文件夹及其所有子文件夹
bash-4.2$ ls -la /opt/tomcat/
total 120
drwxr-xrwx 16 tomcat tomcat 4096 May 21 21:54 .
drwxr-xr-x 5 root root 4096 May 21 21:54 ..
-rw-r----- 1 tomcat tomcat 57092 May 11 21:45 LICENSE
-rw-r----- 1 tomcat tomcat 1804 May 11 21:45 NOTICE
-rw-r----- 1 tomcat tomcat 6708 May 11 21:45 RELEASE-NOTES
-rw-r----- 1 tomcat tomcat 15946 May 11 21:45 RUNNING.txt
drwxr-x--- 2 tomcat tomcat 4096 May 21 21:54 bin
drwx------ 2 tomcat tomcat 4096 May 21 21:54 conf
drwxr-x--- 2 tomcat tomcat 4096 May 21 21:54 lib
drwxr-x--- 2 tomcat tomcat 4096 May 11 21:44 logs
drwxr-x--- 2 tomcat tomcat 4096 May 21 21:54 temp
drwxr-x--- 12 tomcat tomcat 4096 May 21 21:54 webapps
drwxr-x--- 2 tomcat tomcat 4096 May 11 21:44 work
但我不知道为什么禁止用户在他的文件夹中创建文件
bash-4.2$ touch /opt/tomcat/logs/test.txt
touch: cannot touch '/opt/tomcat/logs/test.txt': Permission denied