mirror of https://github.com/alibaba/arthas.git
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
2.8 KiB
Markdown
119 lines
2.8 KiB
Markdown
3 years ago
|
# Docker
|
||
4 years ago
|
|
||
|
## Use JDK in Docker
|
||
|
|
||
|
Many times, the problem that arthas can't work with the application in docker is because the docker does not install JDK, but installs JRE. If only JRE is installed, many JAVA command line tools and class libraries will be missing, and Arthas will not work properly. Here are two common ways to use JDK in Docker.
|
||
|
|
||
|
### Use public JDK image
|
||
|
|
||
3 years ago
|
- https://hub.docker.com/_/openjdk/
|
||
4 years ago
|
|
||
|
such as:
|
||
|
|
||
|
```
|
||
|
FROM openjdk:8-jdk
|
||
|
```
|
||
|
|
||
|
or:
|
||
|
|
||
|
```
|
||
|
FROM openjdk:8-jdk-alpine
|
||
|
```
|
||
|
|
||
|
### Install via package management software
|
||
|
|
||
|
such as:
|
||
|
|
||
|
```bash
|
||
|
# Install OpenJDK-8
|
||
|
RUN apt-get update && \
|
||
|
apt-get install -y openjdk-8-jdk && \
|
||
|
apt-get install -y ant && \
|
||
|
apt-get clean;
|
||
|
|
||
|
# Fix certificate issues
|
||
|
RUN apt-get update && \
|
||
|
apt-get install ca-certificates-java && \
|
||
|
apt-get clean && \
|
||
|
update-ca-certificates -f;
|
||
|
|
||
|
# Setup JAVA_HOME - useful for docker commandline
|
||
|
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64/
|
||
|
RUN export JAVA_HOME
|
||
|
```
|
||
|
|
||
|
or:
|
||
|
|
||
|
```bash
|
||
|
RUN yum install -y \
|
||
|
java-1.8.0-openjdk \
|
||
|
java-1.8.0-openjdk-devel
|
||
|
|
||
|
ENV JAVA_HOME /usr/lib/jvm/java-1.8.0-openjdk/
|
||
|
RUN export JAVA_HOME
|
||
|
```
|
||
|
|
||
6 years ago
|
## Quick start with Docker
|
||
|
|
||
4 years ago
|
1. Delete the existing `math-game` docker container (not necessary)
|
||
6 years ago
|
|
||
3 years ago
|
```sh
|
||
|
$ docker stop math-game || true && docker rm math-game || true
|
||
|
```
|
||
6 years ago
|
|
||
4 years ago
|
1. Start `math-game`
|
||
6 years ago
|
|
||
3 years ago
|
```sh
|
||
|
$ docker run --name math-game -it hengyunabc/arthas:latest /bin/sh -c "java -jar /opt/arthas/math-game.jar"
|
||
|
```
|
||
6 years ago
|
|
||
|
1. Start `arthas-boot` for diagnosis
|
||
|
|
||
3 years ago
|
```sh
|
||
|
$ docker exec -it math-game /bin/sh -c "java -jar /opt/arthas/arthas-boot.jar"
|
||
|
* [1]: 9 jar
|
||
6 years ago
|
|
||
3 years ago
|
[INFO] arthas home: /opt/arthas
|
||
|
[INFO] Try to attach process 9
|
||
|
[INFO] Attach process 9 success.
|
||
|
[INFO] arthas-client connect 127.0.0.1 3658
|
||
|
,---. ,------. ,--------.,--. ,--. ,---. ,---.
|
||
|
/ O \ | .--. ''--. .--'| '--' | / O \ ' .-'
|
||
|
| .-. || '--'.' | | | .--. || .-. |`. `-.
|
||
|
| | | || |\ \ | | | | | || | | |.-' |
|
||
|
`--' `--'`--' '--' `--' `--' `--'`--' `--'`-----'
|
||
6 years ago
|
|
||
|
|
||
3 years ago
|
wiki: https://arthas.aliyun.com/doc
|
||
|
version: 3.0.5
|
||
|
pid: 9
|
||
|
time: 2018-12-18 11:30:36
|
||
|
```
|
||
6 years ago
|
|
||
|
## Diagnose the Java process in Docker
|
||
|
|
||
|
```sh
|
||
5 years ago
|
docker exec -it ${containerId} /bin/bash -c "wget https://arthas.aliyun.com/arthas-boot.jar && java -jar arthas-boot.jar"
|
||
6 years ago
|
```
|
||
|
|
||
|
## Diagnose the Java process in the container in k8s
|
||
|
|
||
|
```sh
|
||
5 years ago
|
kubectl exec -it ${pod} --container ${containerId} -- /bin/bash -c "wget https://arthas.aliyun.com/arthas-boot.jar && java -jar arthas-boot.jar"
|
||
6 years ago
|
```
|
||
|
|
||
|
## Install Arthas into the base Docker image
|
||
|
|
||
|
It's easy to install Arthas into your Docker image.
|
||
|
|
||
|
```
|
||
|
FROM openjdk:8-jdk-alpine
|
||
|
|
||
|
# copy arthas
|
||
|
COPY --from=hengyunabc/arthas:latest /opt/arthas /opt/arthas
|
||
|
```
|
||
|
|
||
6 years ago
|
If you want to specify a version, you can view all the tags:
|
||
|
|
||
3 years ago
|
[https://hub.docker.com/r/hengyunabc/arthas/tags](https://hub.docker.com/r/hengyunabc/arthas/tags)
|