目 录CONTENT

文章目录

根据PID查看对应docker容器

Seven
2024-06-12 / 0 评论 / 0 点赞 / 115 阅读 / 4591 字 / 正在检测是否收录...

根据PID查容器ID

1、已知PID,查找对应容器

cat /proc/${pid}/cgroup

就可以查到对应容器的ID
2、使用PS查看对应容器

docker ps -a |grep '容器ID'

3、根据容器查找对应PID

docker container top 容器名称或容器ID

docker 容器内部无法使用jmap等命令

  • 详细报错信息如下,初步判断是权限问题
root@XXX:/opt/contentCloud/admin# docker exec -it content-cloud bash
root@da515f1d9f7a:/opt/contentCloud/admin# jps          
2512 Jps
8 jar
root@da515f1d9f7a:/opt/contentCloud/admin# jmap -clstats 8
Attaching to process ID 8, please wait...
Error attaching to process: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process: ptrace(PTRACE_ATTACH, ..) failed for 8: Operation not permitted
sun.jvm.hotspot.debugger.DebuggerException: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process: ptrace(PTRACE_ATTACH, ..) failed for 8: Operation not permitted
    at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal$LinuxDebuggerLocalWorkerThread.execute(LinuxDebuggerLocal.java:163)
    at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal.attach(LinuxDebuggerLocal.java:278)
    at sun.jvm.hotspot.HotSpotAgent.attachDebugger(HotSpotAgent.java:671)
    at sun.jvm.hotspot.HotSpotAgent.setupDebuggerLinux(HotSpotAgent.java:611)
    at sun.jvm.hotspot.HotSpotAgent.setupDebugger(HotSpotAgent.java:337)
    at sun.jvm.hotspot.HotSpotAgent.go(HotSpotAgent.java:304)
    at sun.jvm.hotspot.HotSpotAgent.attach(HotSpotAgent.java:140)
    at sun.jvm.hotspot.tools.Tool.start(Tool.java:185)
    at sun.jvm.hotspot.tools.Tool.execute(Tool.java:118)
    at sun.jvm.hotspot.tools.ClassLoaderStats.main(ClassLoaderStats.java:54)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.tools.jmap.JMap.runTool(JMap.java:201)
    at sun.tools.jmap.JMap.main(JMap.java:130)
Caused by: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process: ptrace(PTRACE_ATTACH, ..) failed for 8: Operation not permitted
    at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal.attach0(Native Method)
    at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal.access$100(LinuxDebuggerLocal.java:62)
    at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal$1AttachTask.doit(LinuxDebuggerLocal.java:269)
    at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal$LinuxDebuggerLocalWorkerThread.run(LinuxDebuggerLocal.java:138)
version: '2'
services:
  content1:
    image: xxx/content
    container_name: content
    restart: always
    cap_add:
     - SYS_PTRACE
    expose:
     - 80
    ports:
      - "8080:80"
    volumes:
     ......
  • 原生docker
    docker run –cap -add=SYS_PTRACE
    
0

评论区