Docker查看退出的容器的日志 [英] Docker look at the log of an exited container

查看:2697
本文介绍了Docker查看退出的容器的日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我可以看到已经退出的容器的日志吗?我可以使用 docker ps -a 但是我想知道运行中发生了什么。

解决方案

使用 docker logs 。它也适用于停止的容器,并捕获容器主要过程的整个STDOUT和STDERR流:

  $ docker run -d  - -name test debian echoHello World
02a279c37d5533ecde76976d7f9d1ca986b5e3ec03fac31a38e3dbed5ea65def

$ docker ps -a
CONTAINER ID图像命令创建状态端口名称
49daa9d41a24 debianecho test2分钟前退出(0)2分钟前test

$ docker logs -t test
2016-04-16T15:47:58.988748693Z Hello World


Is there any way I can see the log of a container that has exited?

I can get the container id of the exited container using docker ps -a but I want to know what happened when it was running.

解决方案

Use docker logs. It also works for stopped containers and captures the entire STDOUT and STDERR streams of the container's main process:

$ docker run -d --name test debian echo "Hello World"
02a279c37d5533ecde76976d7f9d1ca986b5e3ec03fac31a38e3dbed5ea65def

$ docker ps -a
CONTAINER ID    IMAGE     COMMAND        CREATED             STATUS                     PORTS               NAMES
49daa9d41a24    debian    "echo test"    2 minutes ago       Exited (0) 2 minutes ago                       test

$ docker logs -t test
2016-04-16T15:47:58.988748693Z Hello World

这篇关于Docker查看退出的容器的日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆