我想知道何时启动了特定的Docker镜像。我可以使用docker images
查找图片。但是使用docker ps -a
未列出图像,因为我们使用--rm
选项运行图像,因此,容器将在结束后立即删除。
是否有某种日志可以判断特定图像何时运行?
我试过docker inspect
,但它不包含我需要的信息。此外,/var/log/docker.log
也没有帮助我。
答案 0 :(得分:3)
最好这样考虑一下:
run
图片,但run
容器基于图片。因此,使用:docker container inspect <your_container_name>
可以获得很多信息,如:
[
{
"Id": "4b9fdc1aa126c24461bfc1309517c0394da7b67af4b92aaedb5d635deb7d4561",
"Created": "2017-12-19T12:36:56.038085061Z",
"Path": "/run.sh",
"Args": [],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 5171,
"ExitCode": 0,
"Error": "",
"StartedAt": "2017-12-20T11:05:50.753491979Z",
"FinishedAt": "2017-12-19T16:49:28.78225137Z"
},
...
我相信你会找:
Created
:通过运行docker run ...
或
StartedAt
:通过运行docker container start ...
启动容器的时间(如果其中started
容器之前为stopped
,则可能已使用此选项)
答案 1 :(得分:1)
您可以使用 docker ps 命令轻松查看状态和正常运行时间。
查找STATUS和CREATED列。
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7ccd6b46a2e9 httpd:2.4 "httpd" 7 minutes ago Up 7 minutes 0.0.0.0:80->80/tcp its-apache
答案 2 :(得分:0)
命令docker ps --filter ancestor=xxx
执行您要查找的内容
参见文档
https://docs.docker.com/engine/reference/commandline/ps/
实施例
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bc07fd1d98a9 k3ck3c/captvty "/bin/sh -c 'WINED..." 5 days ago Up 50 seconds gallant_stallman
2007c8a2344c k3ck3c/captvty_v3_1 "/bin/sh -c 'wine ..." 5 days ago Up 49 seconds cranky_wilson
e06b854ce5ad k3ck3c/captvty "/bin/sh -c 'WINED..." 9 days ago Up 49 seconds quirky_mclean
d24d2a0efafa phusion/baseimage "bash" 11 days ago Up 44 seconds sad_rosalind
ff00ab6e6113 170d69d7c3c8 "/bin/sh -c 'apt-g..." 11 days ago Up 43 seconds competent_ramanujan
6801d8ad513a 596df975d7c3 "/bin/sh -c 'dpkg ..." 2 weeks ago Up 39 seconds loving_nobel
46994fddc6ba solarkennedy/wine-x11-novnc-docker "/usr/bin/supervisord" 2 weeks ago Up 36 seconds 0.0.0.0:8080->8080/tcp naughty_shannon
2070187bf6d2 k3ck3c/captvty "/bin/sh -c 'WINED..." 2 weeks ago Up 36 seconds vibrant_agnesi
b151e3654bab k3ck3c/captvty_v3_1 "/bin/sh -c 'wine ..." 2 weeks ago Up 35 seconds stupefied_brahmagupta
37e30ba9c5cf k3ck3c/captvty "/bin/sh -c 'WINED..." 2 weeks ago Up 35 seconds naughty_boyd
d5f57a41bd0b k3ck3c/captvty "/bin/sh -c 'WINED..." 2 weeks ago Up 34 seconds musing_mahavira
3a10baa66e99 ac68b5fd0b98 "/bin/sh -c 'WINED..." 2 weeks ago Up 34 seconds elegant_thompson
5db88185bf4c 71d3f94833a9 "/bin/sh -c 'WINED..." 3 weeks ago Up 33 seconds vigilant_saha
11b4606ccad2 k3ck3c/apt_cacher "/bin/sh -c 'chmod..." 6 weeks ago Up 31 seconds 0.0.0.0:3142->3142/tcp test_apt_cacher_ng
2da4d5c73b21 monitoringartist/grafana-xxl:latest "/run.sh" 9 months ago Up 19 seconds 0.0.0.0:3000->3000/tcp grafana-xxl2
如果我只想要运行图像的容器k3ck3c / apt_cacher
$ docker ps --filter ancestor=k3ck3c/apt_cacher
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
11b4606ccad2 k3ck3c/apt_cacher "/bin/sh -c 'chmod..." 6 weeks ago Up 58 seconds 0.0.0.0:3142->3142/tcp test_apt_cacher_ng
$
或图片k3ck3c/captvty
$ docker ps --filter ancestor=k3ck3c/captvty
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
bc07fd1d98a9 k3ck3c/captvty "/bin/sh -c 'WINED..." 5 days ago Up 5 minutes gallant_stallman
e06b854ce5ad k3ck3c/captvty "/bin/sh -c 'WINED..." 9 days ago Up 5 minutes quirky_mclean
2070187bf6d2 k3ck3c/captvty "/bin/sh -c 'WINED..." 2 weeks ago Up 4 minutes vibrant_agnesi
37e30ba9c5cf k3ck3c/captvty "/bin/sh -c 'WINED..." 2 weeks ago Up 4 minutes naughty_boyd
d5f57a41bd0b k3ck3c/captvty "/bin/sh -c 'WINED..." 2 weeks ago Up 4 minutes musing_mahavira
$