英文:
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 <container-id> bash
to enter the container, but once I kill -QUIT <process id>
, 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的转储信息,前提是:
docker-compose stop
停止运行的容器而不删除它们;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:
docker-compose stop
stops running containers without removing them;kill -QUIT <process id>
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]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论