Arthas Docker 安装部署手册
·
一、离线安装(推荐)
步骤 1:本地解压
unzip arthas.zip -d ./arthas/
步骤 2:复制到容器
docker cp ./arthas/ <容器名>:/opt/arthas/
步骤 3:进入容器
docker exec -it <容器名> bash
# 若容器没有 bash,用 sh
docker exec -it <容器名> sh
步骤 4:启动 Arthas
cd /opt/arthas
java -jar arthas-boot.jar
启动后会列出所有 Java 进程,输入序号选择目标进程即可。
二、容器内直接下载(需网络)
docker exec -it <容器名> bash
cd /tmp
wget https://arthas.aliyun.com/download/latest_version?mirror=aliyun -O arthas.zip
unzip arthas.zip -d /opt/arthas/
rm arthas.zip
cd /opt/arthas
java -jar arthas-boot.jar
三、Dockerfile 预装(测试环境)
FROM openjdk:8-jdk-alpine
RUN apk add --no-cache wget unzip
RUN wget https://arthas.aliyun.com/download/latest_version?mirror=aliyun -O /tmp/arthas.zip \
&& unzip /tmp/arthas.zip -d /opt/arthas \
&& rm /tmp/arthas.zip
COPY your-app.jar /app/app.jar
CMD ["java", "-jar", "/app/app.jar"]
四、常用调试命令
观察接口参数和返回值
watch com.example.YourController yourMethod "{params, returnObj}" -x 2
- params — 方法入参列表
- returnObj — 方法返回对象
- -x 2 — 展开对象深度 2 层
过滤特定请求
watch com.example.YourController yourMethod "{params, returnObj}" "params[0].id > 100"
观察慢请求
watch com.example.YourController yourMethod "{params, returnObj, cost}" "#cost > 100"
退出 Arthas
- quit — 退出控制台,不清理增强
- stop — 完全停止 Arthas,清除所有增强
五、常见问题
- java: command not found — 容器无 JDK,换用 openjdk:8-jdk 镜像
- tools.jar not found — 用了 JRE 而非 JDK,换用完整 JDK 镜像
- 找不到 unzip — 基础镜像过于精简,用方式一(离线包 docker cp)
- attach 权限不足 —
docker exec -it -u root <容器> bash以 root 进入 - watch 找不到类 — 先用
sc -d <类名>确认完整类路径 - 容器重启后失效 — Arthas 是内存级增强,重启后重新执行即可
安全提醒:Arthas 功能强大,绝对不要在生产环境使用,仅限开发/测试环境
六、速查卡片
# 安装
docker cp ./arthas/ <容器名>:/opt/arthas/
docker exec -it <容器名> bash
cd /opt/arthas && java -jar arthas-boot.jar
调试
watch <类名> <方法名> "{params, returnObj}" -x 2
退出
quit
或
stop更多推荐




所有评论(0)