如何转储容器入口点进程的goroutine?

huangapple go评论98阅读模式
英文:

How to dump goroutine of a container's entry point process?

问题

我有一个由docker-compose up运行的应用程序。当我通过docker-compose stop停止应用程序时,其中一个容器不会终止。该容器运行一个用Go编写的进程,因此我想转储该进程的goroutine以查看进程卡在哪里。

我可以使用docker ps查看容器,并使用docker exec -it <container-id> bash进入容器,但是一旦我执行kill -QUIT <process id>,进程终止后,容器也停止了,因此我无法获取goroutine转储。

在这种情况下如何获取goroutine转储?

英文:

I have an application run by docker-compose up. When a stop the app by docker-compose stop, one of container doesn't terminate. The container run a process written in Go, so I want to dump goroutine of the process to see where the process is stuck.

I can docker ps to see the container, and docker exec -it &lt;container-id&gt; bash to enter the container, but once I kill -QUIT &lt;process id&gt;, as the process terminate, container stopped as well, so I cannot get goroutine dump.

How to get goroutine dump in this case?

答案1

得分: 2

我认为你可以从容器的日志中获取goroutine的转储信息,前提是:

  1. docker-compose stop 停止运行的容器而不删除它们;
  2. kill -QUIT <进程ID> 将goroutine转储到标准错误输出。

以下是获取容器日志的docker命令(-n 指定从日志末尾显示的行数):

$ docker logs -n 1000 [容器名称]
英文:

> container stopped as well, so I cannot get goroutine dump.

I think you can get the goroutine dump from the logs of the container, providing that:

  1. docker-compose stop stops running containers without removing them;
  2. kill -QUIT &lt;process id&gt; dumps the goroutine to the stderr.

Here is the docker command to get the container logs (-n specifies the number of lines to show from the end of the logs):

$ docker logs -n 1000 [container-name]

huangapple
  • 本文由 发表于 2023年5月12日 22:16:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76237206.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定