英文:
How to check container uptime from inside docker container (without docker installed in container)?
问题
如何在 Docker 容器内部检查容器的运行时间,而不需要在容器内安装 Docker?
-
uptime
提供主机机器的运行时间 -
last reboot
尝试读取/var/log/wtmp
并不输出任何内容 -
docker ps
可以提供容器的运行时间,但我在容器内无法使用它
英文:
How to check container uptime from inside docker container without having docker installed in the container?
-
uptime
gives the uptime of the host machine -
last reboot
tries to read/var/log/wtmp
and outputs nothing -
docker ps
would give the uptime, but I don't have it inside the container
答案1
得分: 1
第一个进程启动时间可以作为容器启动时间:
/var/app# stat /proc/1
文件:/proc/1
大小:0 块:0 IO 块:1024 目录
设备:91h/145d Inode:19102 链接:9
访问:(0555/dr-xr-xr-x) 用户ID:(0/ root) 组ID:(0/ root)
访问:2023-05-08 13:08:14.000000000
修改:2023-05-08 13:08:14.000000000
更改:2023-05-08 13:08:14.000000000
英文:
The first process start time could be used as container start time:
/var/app # stat /proc/1
File: /proc/1
Size: 0 Blocks: 0 IO Block: 1024 directory
Device: 91h/145d Inode: 19102 Links: 9
Access: (0555/dr-xr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2023-05-08 13:08:14.000000000
Modify: 2023-05-08 13:08:14.000000000
Change: 2023-05-08 13:08:14.000000000
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论