FROM centos:7.2.1511 MAINTAINER zhu <[email protected]> #Create a directory RUN mkdir -p /xx/java/jdk1.8.0_151 #Add the jdk folder in the current directory to the mirror ADD jdk1.8.0_151 /xx/java/jdk1.8.0_151 #Create tomcat directory RUN mkdir -p /xx/apache-tomcat-7.0.82 #Add the tomcat folder in the current directory to the mirror ADD apache-tomcat-7.0.82 /xx/apache-tomcat-7.0.82 #Add environment variables ENV JAVA_HOME=/xx/java/jdk1.8.0_151 ENV CLASSPATH=.:${JAVA_HOME}/jre/lib/rt.jar:${JAVA_HOME}/lib/tools.jar:${JAVA_HOME}/lib/dt.jar ENV PATH=$PATH:$JAVA_HOME/bin ENV CATALINA_HOME=/xx/apache-tomcat-7.0.82 ENV PATH=$PATH:${CATALINA_HOME}/bin # Expose port 8080 EXPOSE 8080 CMD ["/xx/apache-tomcat-7.0.82/bin/catalina.sh","run"]
CMD must be written in this way. Other CMD bash xx.sh is also not easy to use
And it must be catalina.sh, and it is not easy to replace it with startup.sh.
docker logs container id View container startup logs
reason:
catalina.sh
touch "$CATALINA_OUT"
if [ "$1" = "-security" ] ; then
if [ $have_tty -eq 1 ]; then
echo "Using Security Manager"
fi
shift
eval $_NOHUP "\"$_RUNJAVA\"" "\"$LOGGING_CONFIG\"" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \
-Djava.endorsed.dirs="\"$JAVA_ENDORSED_DIRS\"" -classpath "\"$CLASSPATH\"" \
-Djava.security.manager \
-Djava.security.policy=="\"$CATALINA_BASE/conf/catalina.policy\"" \
-Dcatalina.base="\"$CATALINA_BASE\"" \
-Dcatalina.home="\"$CATALINA_HOME\"" \
-Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \
org.apache.catalina.startup.Bootstrap "$@" start \
>> "$CATALINA_OUT" 2>&1 "&"
else
eval $_NOHUP "\"$_RUNJAVA\"" "\"$LOGGING_CONFIG\"" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \
-Djava.endorsed.dirs="\"$JAVA_ENDORSED_DIRS\"" -classpath "\"$CLASSPATH\"" \
-Dcatalina.base="\"$CATALINA_BASE\"" \
-Dcatalina.home="\"$CATALINA_HOME\"" \
-Djava.io.tmpdir="\"$CATALINA_TMPDIR\"" \
org.apache.catalina.startup.Bootstrap "$@" start \
>> "$CATALINA_OUT" 2>&1 "&"
be
Remove the above red part, you can use startup.sh
CMD bash /daas/apache-tomcat-7.0.82/bin/startup.sh
also ok
2. Generate imagedocker build -t custom image name: tag .
For example:
docker build -t jdk1.8.tomcat7:0.0.1 .
3. Run
docker run --name zcy1 -d -p 8020:8080 720902d110bc
Verify that the startup was successful
docker ps
If there is, the startup is successful, otherwise it fails, you need to delete the container, delete the image, and make a new one
docker rm container id
docker rmi image
that
the tomcat page appears when visiting ip:8020
5. Debug the dockerfile
to enter the container, and check whether the operation in the dockerfile takes effect in the container