Docker中查看已经崩溃的容器的日志
容器崩溃后,查看该容器的日志,有助于分析崩溃的原因,并在后续迭代版本中修复问题。
一般情况下,使用docker ps命令可以列出正在运行的容器的列表。例如:
[root@li1102-98 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
96d8758da4f5 hxcan/assess-stock-serrver:501 "./AssessStockServ..." 8 hours ago Up 8 hours 0.0.0.0:12091->12091/udp nostalgic_bardeen
如果上面列出的 96d8758da4f5容器在某个时刻崩溃了,之后你再docker ps,就看到一个空列表了。例如:
[g@c ~]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
要对容器进行查询或操作的话,需使用docker container命令。具体地,要列出容器列表的话,使用docker container ls命令。此处我们需要将已经崩溃的容器也列出,就需要加上-a参数,也就是docker container ls -a。例如:
[root@li1102-98 ~]# docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
96d8758da4f5 hxcan/assess-stock-serrver:501 "./AssessStockServ..." 8 hours ago Up 8 hours 0.0.0.0:12091->12091/udp nostalgic_bardeen
94b6f0f580fa hxcan/assess-stock-serrver:498 "./AssessStockServ..." 9 hours ago Exited (1) 9 hours ago infallible_goldwasser
5152c990fb1e hxcan/assess-stock-serrver:494 "./AssessStockServ..." 4 days ago Exited (1) 9 hours ago romantic_goldstine
10355709d6cf hxcan/assess-stock-serrver:491 "./AssessStockServ..." 4 days ago Exited (1) 4 days ago unruffled_goodall
7d55d01f934c hxcan/assess-stock-serrver:488 "./AssessStockServ..." 5 days ago Exited (1) 4 days ago vibrant_murdock
54d834caae08 hxcan/assess-stock-serrver:475 "./AssessStockServ..." 7 days ago Exited (1) 5 days ago adoring_ramanujan
a5052c02c6bd hxcan/assess-stock-serrver:477 "./AssessStockServ..." 7 days ago Exited (1) 7 days ago naughty_babbage
e29d97a00da4 hxcan/assess-stock-serrver:467 "./AssessStockServ..." 12 days ago Exited (1) 7 days ago kind_brown
3426f7a91557 hxcan/assess-stock-serrver:461 "./AssessStockServ..." 12 days ago Exited (1) 12 days ago lucid_panini
bf7c24d496bd hxcan/assess-stock-serrver:451 "./AssessStockServ..." 2 weeks ago Exited (1) 12 days ago modest_haibt
808f751a5be8 hxcan/assess-stock-serrver:447 "./AssessStockServ..." 2 weeks ago Exited (1) 2 weeks ago hungry_visvesvaraya
9fd2eecf6131 hxcan/assess-stock-serrver:435 "./AssessStockServ..." 2 weeks ago Exited (1) 2 weeks ago laughing_brown
361b033bae66 hxcan/assess-stock-serrver:413 "./AssessStockServ..." 2 weeks ago Exited (1) 2 weeks ago clever_ritchie
59c4931007c2 hxcan/assess-stock-serrver:366 "./AssessStockServ..." 3 weeks ago Exited (1) 2 weeks ago stupefied_lewin
bc5ff8358f1a hxcan/assess-stock-serrver:299 "./AssessStockServ..." 3 weeks ago Exited (1) 3 weeks ago pedantic_archimedes
3834633c2587 hxcan/assess-stock-serrver:299 "./AssessStockServ..." 3 weeks ago Exited (1) 3 weeks ago frosty_brattain
从上面的结果可以看到 , 94b6f0f580fa以及下面的容器,都是处于退出状态。它们可能是之前明确地手动终止掉的,也可能是之前崩溃了的。此处,作者明确地知道, 94b6f0f580fa是崩溃了的。下面就看它的日志。
使用docker logs命令来查看指定容器的日志。例如:
[root@li1102-98 ~]# docker logs 94b6f0f580fa
……省掉一部分……
2020-08-11T02:14:55+00:00 : Received �hfunctionwGenerateRandomStockCode
2775
002711
2020-08-11T02:14:57+00:00 : Received �hfunctionrStockAssessRequestistockCodef002711jmoneyInput�@�F�nexpectedProfit�@��
from /usr/src/app/AssessStock/AA1FA62F0BE8DCDD7C1C4A739AA0CE97.jpg_.rb:97:in `calculateHoldResult'
from /usr/src/app/AssessStock/AA1FA62F0BE8DCDD7C1C4A739AA0CE97.jpg_.rb:202:in `block in assessStock'
from /usr/src/app/AssessStock/AA1FA62F0BE8DCDD7C1C4A739AA0CE97.jpg_.rb:198:in `each'
from /usr/src/app/AssessStock/AA1FA62F0BE8DCDD7C1C4A739AA0CE97.jpg_.rb:198:in `assessStock'
from ./AssessStockServer.cache.rb:62:in `assessStock'
from ./AssessStockServer.cache.rb:37:in `processMessage'
from ./AssessStockServer.cache.rb:19:in `receive_data'
from /usr/local/bundle/gems/eventmachine-1.2.7/lib/eventmachine.rb:195:in `run_machine'
from /usr/local/bundle/gems/eventmachine-1.2.7/lib/eventmachine.rb:195:in `run'
from ./AssessStockServer.cache.rb:73:in `<main>'
作为这个容器中代码的作者,看到这里,就知道是代码的哪里出错了,并且知道了触发该错误的参数。之后使用这样的参数在本地复现,就可以找到崩溃的原因,再对应地处理掉问题了。
第八章 第一节
西北地区
自然特征与农业
离子波
应用页面设计
Your opinionsHxLauncher: Launch Android applications by voice commands