引言
在docker或者k8s上运行了第三方的应用,很多时候我们都想知道运行流程,一般都会docker或者k8s容器中获取jar包。
那么该如何把里面的jar包提取出来呢?
其实有两种方式,分别为:
从镜像信息获取
进入容器获取
从镜像信息获取
首先,查看镜像:
docker image ls |grep <你想要找到镜像名>
查看镜像内容:
docker inspect <镜像ID>
内容大概如下:
[{"Id": "sha256:24cc0d9dcf54471b1bb2b63610ffaead977409b784c0fdeab7712d86b3b77663","RepoTags": ["xuxueli/xxl-job-admin:2.3.0"],"RepoDigests": ["xuxueli/xxl-job-admin@sha256:3dc5f442c64b44c97e5b5278df259bc29a8c6b130bee903b6a004d6d00302766"],"Parent": "","Comment": "","Created": "2021-02-09T08:56:42.0962399Z","Container": "4f8f019e52e19221958105a1c5788bfdcb0decc85dd5106fd083abf190a0006c","ContainerConfig": {"Hostname": "4f8f019e52e1","Domainname": "","User": "","AttachStdin": false,"AttachStdout": false,"AttachStderr": false,"Tty": false,"OpenStdin": false,"StdinOnce": false,"Env": ["PATH=/usr/local/openjdk-8/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","LANG=C.UTF-8","JAVA_HOME=/usr/local/openjdk-8","JAVA_VERSION=8u265","PARAMS=","TZ=PRC"],"Cmd": ["/bin/sh","-c","#(nop) ","ENTRYPOINT [\"sh\" \"-c\" \"java -jar $JAVA_OPTS /app.jar $PARAMS\"]"],"Image": "sha256:a2946f81fc1e7ec6b9385a14623e3217be1034d5313f933d7ac0d6868d67edac","Volumes": null,"WorkingDir": "","Entrypoint": ["sh","-c","java -jar $JAVA_OPTS /app.jar $PARAMS"],"OnBuild": null,"Labels": {}},"DockerVersion": "19.03.12","Author": "xuxueli","Config": {"Hostname": "","Domainname": "","User": "","AttachStdin": false,"AttachStdout": false,"AttachStderr": false,"Tty": false,"OpenStdin": false,"StdinOnce": false,"Env": ["PATH=/usr/local/openjdk-8/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","LANG=C.UTF-8","JAVA_HOME=/usr/local/openjdk-8","JAVA_VERSION=8u265","PARAMS=","TZ=PRC"],"Cmd": null,"Image": "sha256:a2946f81fc1e7ec6b9385a14623e3217be1034d5313f933d7ac0d6868d67edac","Volumes": null,"WorkingDir": "","Entrypoint": ["sh","-c","java -jar $JAVA_OPTS /app.jar $PARAMS"],"OnBuild": null,"Labels": null},"Architecture": "amd64","Os": "linux","Size": 223053204,"VirtualSize": 223053204,"GraphDriver": {"Data": {"LowerDir": "/var/lib/docker/overlay2/370de9d34af94c06305c6d77b2b18c9e6f9a65ef0a081722311b5d2d4dae03bb/diff:/var/lib/docker/overlay2/c7628695c23a5be652d30f9bd54808ef7e3ae33b1a2d44845213f37a8de8f45a/diff:/var/lib/docker/overlay2/5855b68925bb36ab1672a12942e89b2f7b13054bcf3f630dff6680ba0bb7b7a4/diff:/var/lib/docker/overlay2/6f35414475cdb5959cecfa1bb5ac7555b126b1b0e1750d29ed701b33ed77b09b/diff:/var/lib/docker/overlay2/86344e5893741d6757a7be24dfd8a3502af0c130cae2e05f46e405e70285a3bd/diff","MergedDir": "/var/lib/docker/overlay2/4857c5be1f7f9f2a293ae474a7af157e5d5a2ff5b37c8d3232ea4773fe87fc04/merged","UpperDir": "/var/lib/docker/overlay2/4857c5be1f7f9f2a293ae474a7af157e5d5a2ff5b37c8d3232ea4773fe87fc04/diff","WorkDir": "/var/lib/docker/overlay2/4857c5be1f7f9f2a293ae474a7af157e5d5a2ff5b37c8d3232ea4773fe87fc04/work"},"Name": "overlay2"},"RootFS": {"Type": "layers","Layers": ["sha256:d0f104dc0a1f9c744b65b23b3fd4d4d3236b4656e67f776fe13f8ad8423b955c","sha256:95c20fa5728d237b86ad3a7f2997e3ad71ec472165297872c119108de68e7114","sha256:ed7152ed4cbd0de85948780e8b33ffe66728f56b864bb8db4b520089b48c4883","sha256:43ee8102614ddbd62242c06c4a2f7dc50fd81a9dbd72daf75467c65264d95d4f","sha256:c39ce324e48b7719700a03f89eb594479ef4f4f5bce554b249346b9ecf72f3fd","sha256:13562a79b4ca55a6dd7b3c2eb8cc58f28009156971ca07348d0f4cc52941d2ea"]},"Metadata": {"LastTagTime": "0001-01-01T00:00:00Z"}}
]
从内容中,可以看到打包镜像的流程,其中CMD的标签和环境变量,可以看出使用java来执行程序,依赖库及执行程序入口如下:
一般jar包在UpperDir:
进入对应的路径:
cd /var/lib/docker/overlay2/4857c5be1f7f9f2a293ae474a7af157e5d5a2ff5b37c8d3232ea4773fe87fc04/diff
可以看到里面有对应的文件和jar包,如果还没有,只能进入容器查看了。
进入容器获取(推荐)
进入k8s容器命令:
kubectl exec -it pod名称 -n命名空间 bash
进入docker容器命令:
docker exec -it container名称 /bin/sh
看看里面有什么内容:
将容器中的jar包复制到本地目录:
可以看到此目录已经含有所有程序运行时需要的内容了。
参考🔗
https://mp.weixin.qq.com/s/S0hshZhCL-lEn9CVDAhHPA
原创 架构与源码