Docker reports error when running tomcat
Cannot find /usr/local/tomcat/bin/setclasspath.sh This file is needed to run this program
After trying, use the dockerfile package to add the command
RUN unset CATALINA_HOME
didn’t work after trying
After searching, there is an article with the same problem: https://www.5axxw.com/questions/content/fypkh1
The specific investigation process is as follows
The prompt is that setclasspath.sh cannot be found, because this tomcat restarts repeatedly,
So use the command to copy a bin directory to the current folder
docker cp container id:/usr/local/tomcat/bin ./
It turns out that setclasspath.sh exists, so what is the problem? Look for the error-reporting code
In the catalina.sh script, the part causing the problem is the following:
if [ -r "$CATALINA_HOME"/bin/setclasspath.sh ]; then . "$CATALINA_HOME"/bin/setclasspath.sh else echo "Cannot find $CATALINA_HOME/bin/setclasspath.sh" echo "This file is needed to run this program" fi
The square brackets plus the -r command means to test whether the file is read-only, similar to -x to test whether the file is executable
On the system in question, the -r command invocation in the container is not normal.
try to start a temporary tomcat8 verification,
docker run -it --rm --entrypoint=/bin/bash tomcat:8
Note: Executing the docker run command with the –rm command option is equivalent to executing docker rm -v after the container exits.
Excuting an order
root@f338debf92f6:/usr/local/tomcat# [[ -r /bin/bash ]] root@f338debf92f6:/usr/local/tomcat# echo $? 1
Execute on a normal system
root@0083a80a9ec2:/usr/local/tomcat# [[ -r /bin/bash ]] root@0083a80a9ec2:/usr/local/tomcat# echo $? 0
$? command Indicates the exit status of the previous command, or the return value of a function.
For exit status 0 means no error, any other value means error. In general, most commands will return 0 if they are executed successfully, and 1 if they fail, and some commands will return other values, indicating different types of errors.
How to solve?
This is related to the faccessat2 system call, which will fail if your kernel doesn’t support faccessat2 due to a bug in runc . There is an article saying that upgrading the kernel to 5.8 or above may work. I tried it and it didn’t work, because the kernel with the problem was 5.10.
Method 1: Update runc >= 1.0.0-rc93
Method 2: –privileged switch to run the container
The specific implementation of method 1:
View the original runc version
runc -v
Download runc.amd64 version 1.0.0-rc95
Download address: Releases · opencontainers/runc · GitHub
Rename and execute permission
mv runc.amd64 runc & amp; & amp; chmod +x runc
View and backup the original runc
whereis runc
Some systems are in the /usr/bin/ directory, and some systems are in the /usr/local/bin/ directory. The following commands are based on /usr/local/bin/ and change the directory of /usr/bin/
mv /usr/local/bin/runc /usr/local/bin/runcbak
Overwrite the original runc
cp runc /usr/local/bin/runc
Check out the new version of runc
runc -v
Method 2 specific implementation
docker run execute
docker run --privileged=true -p 8080:8080 tomcat:8
docker-compose.yml add
version: '2' services: tomcat: container_name: tomcat image: tomcat:8 ports: - '8080:8080' environment: - TZ=Asia/Shanghai privileged: true restart: always