For specific content, please refer to the official documentation, each command has a detailed description: https://arthas.aliyun.com/doc/ This article does not introduce how to use arthas. What we want to talk about here is how to use arthas in our docker container. Since it is rather cumbersome to use arthas in a docker container, we need to find the container ID, copy the entire arthas directory to the container, enter the container, switch to the user of the target service, and start arthas. These steps are not friendly to many students who are not familiar with Linux commands and docker commands. Therefore, I wrote a script that can directly replace the above steps. The effect is shown in the figure below: Simply enter the complete service name (here the IMAGE name of the container) after the script and you can use it. It is simple and convenient. How to use: First, you need to unzip arhas-bin.zip on the Linux server, and the unzipped version is the arthas software. Make sure Docker is installed on your machine arhas-bin.zip download directory: https://github.com/alibaba/arthas/releases Put the arthasDocker.sh script into the arthas directory you just unzipped, open the script, edit the Contents of the arthasDocker.sh script: #!/bin/bash # # author: dijia478 # date: 2020-8-20 18:14:38 # desc: This script needs to be placed in the arthas directory and copied into the docker container along with the entire directory. The main purpose is to switch the user of the target service in the container and start arthas echo "Start querying the process ID and user of the target service..." PID=`ps -eo pid,user=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -o args | grep java | grep -v grep | awk '{print $1}'` echo "The process id of the target service is ${PID}" USER=`ps -eo pid,user=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -o args | grep java | grep -v grep | awk '{print $2}'` echo "The user of the target service is ${USER}" if [[ ! -d "/home/${USER}" ]] then mkdir -p /home/${USER} echo "Create directory /home/${USER}" fi chmod 777 /home/${USER} echo "Start switching users and starting arthas..." # The following arthas path needs to be modified and should be consistent with the startArthas.sh script ARTHAS_PATH="/opt/arthas" su ${USER} -c "java -jar ${ARTHAS_PATH}/arthas-client.jar 127.0.0.1 3658 -c 'stop'" su ${USER} -c "java -jar ${ARTHAS_PATH}/arthas-boot.jar ${PID}" Put the startArthas.sh script on the Linux server, it is recommended to put it in the ~ directory, open the script, edit the startArthas.sh script content: #!/bin/bash # # author: dijia478 # date: 2020-9-18 10:36:27 # desc: The main purpose of this script is to start the arthas diagnostic tool to diagnose a java service in a docker if [[ ${1} == '' ]] then echo "Please select a service:" sudo docker ps | awk 'NR>1 {print $2}' exit 0 fi echo "Starting to search for container for service ${1}..." DOCKER_LIST=`sudo docker ps | awk 'NR>1 {print $2}'` FLAG=0 for i in ${DOCKER_LIST[@]} do if [[ ${i} == ${1} ]] then FLAG=1 break fi done if [[ ${FLAG} == 0 ]] then DOCKER_NAME=`sudo docker ps | awk 'NR>1 {print $2}' | grep ${1}` if [[ ${DOCKER_NAME} == '' ]] then echo "The container for this service was not found. Please reselect the service:" sudo docker ps | awk 'NR>1 {print $2}' else echo "Please enter the full name of the service:" sudo docker ps | awk 'NR>1 {print $2}' | grep ${1} fi else ID=`sudo docker ps --filter ancestor=${1} | awk '{print $1}' | sed -n '2p'` echo "Found container ${ID}" echo "Start copying arthas to the container..." # The following arthas path needs to be modified and should be consistent with the arthasDocker.sh script ARTHAS_PATH="/opt/arthas" sudo docker exec -it ${ID} /bin/bash -c "rm -rf ${ARTHAS_PATH}" sudo docker cp ${ARTHAS_PATH} ${ID}:${ARTHAS_PATH} echo "Copy completed" echo "About to enter the container..." sudo docker exec -it ${ID} /bin/bash -c "bash ${ARTHAS_PATH}/arthasDocker.sh" fi Finally, just run the startArthas.sh script © Copyright Statement The copyright of the article belongs to the author. Reprinting is welcome, but the original link must be given, otherwise the right to pursue legal liability is reserved. THE END This is the end of this article on how to use Arthas in Docker containers. For more information about using Arthas with Docker, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Sharing experience on the priority of CSS style loading
>>: How to hide and remove scroll bars in HTML
Students who use Ansible know that Ansible only s...
The requirement is to pass in the rating data for...
I will use three days to complete the static page...
Table of contents Problem description: Solution 1...
1. Download mysql-5.7.21-windowx64.zip from the o...
Experimental environment: Physical machine Window...
1. What are the formats of lines? You can see you...
The content of the written Dockerfile is: FROM py...
Table of contents 1. Preprocessing 2. Compilation...
This article shares the specific code of js to im...
As shown below: select name from mysql.proc where...
Mysql is a popular and easy-to-use database softw...
In MySQL, you can use IF(), IFNULL(), NULLIF(), a...
Create a project directory mkdir php Create the f...
This article example shares the specific code of ...