preface

  • In real development, projects typically run ondockerInside the container, learnArthasBefore, you need to build the container environment
  • usedocker pull tomcatCommand from thedocker HubThe image that you pull down, you useopenJdk, it does not contain usejpsCommand, executejava -jar arthas.jarStart thearthas, an error is reported indicating that the Java Process could not be found

1. Before building the Tomcat+Jdk environment, download the Tomcat and Jdk installation packages

Download tomcat8.5 Download jdk1.8

2. Create a Dockerfile file and generate an image

  • Upload tomcat and JDK to Linux
  • Create a Dockerfile file with the following contentsCMD ["/usr/local/apache tomcat - 8.5.31 / bin/catalina. Sh ", "run"]You can usedocker logsLogs are displayed.CMD /usr/local/apache-tomcat-8.5.31/bin/startup.sh && tail -F /usr/local/apache-tomcat-8.5.31/logs/catalina.outLogs will be placed oncatalina.outIn the file, indocker runYou need to configure the log mount function for viewing logsdocker logsUnable to view logs
MAINTAINER Easysan <[email protected]> # ADD Java and Tomcat to the container JDK -8u212-linux-x64.tar.gz /usr/local ADD apache-tomcat-8.5.31.tar.gz /usr/local RUN yum -y install vim Set WORKDIR to WORKDIR Configure the Java and Tomcat environment variables ENV JAVA_HOME /usr/local/jdk1.8.0_212 ENV CLASSPATH $JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar ENV CATALINA_HOME /usr/local/apache-tomcat-8.5.31 ENV CATALINA_BASE /usr/local/apache-tomcat-8.5.31 ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/lib:$CATALINA_HOME/bin # ENTRYPOINT ["/usr/local/apache-tomcat-9.0.8/bin/startup.sh"] CMD ["/usr/local/apache-tomcat-8.5.31/bin/catalina.sh","run"] # CMD /usr/local/apache-tomcat-8.5.31/bin/startup.sh && tail -f/usr/local/apache tomcat - 8.5.31 / logs/catalina. OutCopy the code
  • In the directory/mydata/tomcatuseDocker build-t arthas-tomcat:v1.1.0.Create a mirror image

3. Start the container

Docker run - p - 9999-8080 the name arthas_tomcat - v/mydata/tomcat/webapps / : / usr/local/apache tomcat -- 8.5.31 / webapps - v The/etc/localtime: / etc/localtime: arthas ro - d - tomcat: v1.1.0Copy the code

4. Create a simple Spring Boot project and upload the war package/mydata/tomcat/webapps/Directory, restart the containerdocker restart 9b87fdb14cb2

5. Download and start Arthas,For details, please refer to the official website

  • Into the containerdocker exec -it 9b87fdb14cb2 /bin/bash, where the directory is/usr/local. The new directorymkdir arthasEnter thecd arthasThe arthas.jar directory where you downloaded arthas.jar
  • downloadcurl -O https://arthas.aliyun.com/arthas-boot.jarAnd start thejava -jar arthas.jar
  • Select the sequence number of the Java process

6.Arthas- Container environment setup is complete