容器实现原理

容器实现原理,第1张

docker容器状态的转换实现

本文主要介绍docker容器状态转换的实现,有很好的参考价值,希望对你有所帮助。来和边肖一起看看吧。

一个docker容器状态转换图

两次实战

[root@localhost~]#dockerinfo Containers:0 Running:0 Paused:0 Stopped:0 Images:3 ServerVersion:17.09.0-ce StorageDriver:overlay BackingFilesystem:xfs Supportsd_type:false LoggingDriver:json-file CgroupDriver:cgroupfs Plugins: Volume:local Network:bridgehostmacvlannulloverlay Log:awslogsfluentdgcplogsgelfjournaldjson-filelogentriessplunksyslog Swarm:inactive Runtimes:runc DefaultRuntime:runc InitBinary:docker-init containerdversion:06b9cb35161009dcb7123345749fef02f7cea8e0 runcversion:3f2f8b84a77f73d38244dd690525642a72156c64 initversion:949e6fa SecurityOptions: seccomp Profile:default KernelVersion:3.10.0-327.el7.x86_64 OperatingSystem:CentOSLinux7(Core) OSType:linux Architecture:x86_64 CPUs:1 TotalMemory:993MiB Name:localhost.localdomain ID:6ULL:CFMN:YT7C:4RXZ:2CJ4:26H2:D4Y6:YHUP:SH7L:QLEQ:AWEB:EWTB DockerRootDir:/var/lib/docker DebugMode(client):false DebugMode(server):false Registry:https://index.docker.io/v1/ Experimental:false InsecureRegistries: 127.0.0.0/8 LiveRestoreEnabled:false WARNING:overlay:thebackingxfsfilesystemisformattedwithoutd_typesupport,whichleadstoincorrectbehavior. Reformatthefilesystemwithftype=1toenabled_typesupport. Runningwithoutd_typesupportwillnotbesupportedinfuturereleases. WARNING:bridge-nf-call-iptablesisdisabled WARNING:bridge-nf-call-ip6tablesisdisabled [root@localhost~]#dockerimages REPOSITORYTAGIMAGEIDCREATEDSIZE clearlinuxlatest32685d1140026daysago62.5MB busyboxlatest6ad733544a636daysago1.13MB alpinelatest053cde6e89536daysago3.96MB [root@localhost~]#dockerrun-d--namebox1busybox 4ca3d293206cd34e449075491679b0cddd619b451cac7a3d20d5b5daaa6095d8 [root@localhost~]#dockerrun-itd--namebox2busybox 9c1578a50f0b97d48c7501dda6d6e1c3d8b3d9ed0e37416120f91f5a634fb12f [root@localhost~]#dockerps-a CONTAINERIDIMAGECOMMANDCREATEDSTATUSPORTSNAMES 9c1578a50f0bbusybox"sh"13secondsagoUp11secondsbox2 4ca3d293206cbusybox"sh"47secondsagoExited(0)45secondsagobox1 [root@localhost~]#dockerrun-itd--namebox3busybox e84a746ea040603aa4db791da77aee2e2502ff5b184e89049a74805671a58ba9 [root@localhost~]#dockerps-a CONTAINERIDIMAGECOMMANDCREATEDSTATUSPORTSNAMES e84a746ea040busybox"sh"5secondsagoUp4secondsbox3 9c1578a50f0bbusybox"sh"AboutaminuteagoUpAboutaminutebox2 4ca3d293206cbusybox"sh"2minutesagoExited(0)2minutesago box1 [root@localhost~]#dockerinfo Containers:3 Running:2 Paused:0 Stopped:1 Images:3 ServerVersion:17.09.0-ce StorageDriver:overlay BackingFilesystem:xfs Supportsd_type:false LoggingDriver:json-file CgroupDriver:cgroupfs Plugins: Volume:local Network:bridgehostmacvlannulloverlay Log:awslogsfluentdgcplogsgelfjournaldjson-filelogentriessplunksyslog Swarm:inactive Runtimes:runc DefaultRuntime:runc InitBinary:docker-init containerdversion:06b9cb35161009dcb7123345749fef02f7cea8e0 runcversion:3f2f8b84a77f73d38244dd690525642a72156c64 initversion:949e6fa SecurityOptions: seccomp Profile:default KernelVersion:3.10.0-327.el7.x86_64 OperatingSystem:CentOSLinux7(Core) OSType:linux Architecture:x86_64 CPUs:1 TotalMemory:993MiB Name:localhost.localdomain ID:6ULL:CFMN:YT7C:4RXZ:2CJ4:26H2:D4Y6:YHUP:SH7L:QLEQ:AWEB:EWTB DockerRootDir:/var/lib/docker DebugMode(client):false DebugMode(server):false Registry:https://index.docker.io/v1/ Experimental:false InsecureRegistries: 127.0.0.0/8 LiveRestoreEnabled:false WARNING:overlay:thebackingxfsfilesystemisformattedwithoutd_typesupport,whichleadstoincorrectbehavior. Reformatthefilesystemwithftype=1toenabled_typesupport. Runningwithoutd_typesupportwillnotbesupportedinfuturereleases. WARNING:bridge-nf-call-iptablesisdisabled WARNING:bridge-nf-call-ip6tablesisdisabled [root@localhost~]#dockerps-a CONTAINERIDIMAGECOMMANDCREATEDSTATUSPORTSNAMES e84a746ea040busybox"sh"4minutesagoUp4minutesbox3 9c1578a50f0bbusybox"sh"6minutesagoUp6minutesbox2 4ca3d293206cbusybox"sh"6minutesagoExited(0)6minutesagobox1 [root@localhost~]#dockerrestart9c 9c [root@localhost~]#dockerps-a CONTAINERIDIMAGECOMMANDCREATEDSTATUSPORTSNAMES e84a746ea040busybox"sh"5minutesagoUp5minutesbox3 9c1578a50f0bbusybox"sh"7minutesagoUp2secondsbox2 4ca3d293206cbusybox"sh"8minutesagoExited(0)8minutesagobox1 [root@localhost~]#dockerpause9c 9c [root@localhost~]#dockerps-a CONTAINERIDIMAGECOMMANDCREATEDSTATUSPORTSNAMES e84a746ea040busybox"sh"8minutesagoUp8minutesbox3 9c1578a50f0bbusybox"sh"10minutesagoUp2minutes(Paused)box2 4ca3d293206cbusybox"sh"10minutesagoExited(0)10minutesagobox1 [root@localhost~]#dockerinfo Containers:3 Running:1 Paused:1 Stopped:1 Images:3 ServerVersion:17.09.0-ce StorageDriver:overlay BackingFilesystem:xfs Supportsd_type:false LoggingDriver:json-file CgroupDriver:cgroupfs Plugins: Volume:local Network:bridgehostmacvlannulloverlay Log:awslogsfluentdgcplogsgelfjournaldjson-filelogentriessplunksyslog Swarm:inactive Runtimes:runc DefaultRuntime:runc InitBinary:docker-init containerdversion:06b9cb35161009dcb7123345749fef02f7cea8e0 runcversion:3f2f8b84a77f73d38244dd690525642a72156c64 initversion:949e6fa SecurityOptions: seccomp Profile:default KernelVersion:3.10.0-327.el7.x86_64 OperatingSystem:CentOSLinux7(Core) OSType:linux Architecture:x86_64 CPUs:1 TotalMemory:993MiB Name:localhost.localdomain ID:6ULL:CFMN:YT7C:4RXZ:2CJ4:26H2:D4Y6:YHUP:SH7L:QLEQ:AWEB:EWTB DockerRootDir:/var/lib/docker DebugMode(client):false DebugMode(server):false Registry:https://index.docker.io/v1/ Experimental:false InsecureRegistries: 127.0.0.0/8 LiveRestoreEnabled:false WARNING:overlay:thebackingxfsfilesystemisformattedwithoutd_typesupport,whichleadstoincorrectbehavior. Reformatthefilesystemwithftype=1toenabled_typesupport. Runningwithoutd_typesupportwillnotbesupportedinfuturereleases. WARNING:bridge-nf-call-iptablesisdisabled WARNING:bridge-nf-call-ip6tablesisdisabled [root@localhost~]#dockerunpause9c 9c [root@localhost~]#dockerps-a CONTAINERIDIMAGECOMMANDCREATEDSTATUSPORTSNAMES e84a746ea040busybox"sh"11minutesagoUp11minutesbox3 9c1578a50f0bbusybox"sh"13minutesagoUp6minutesbox2 4ca3d293206cbusybox"sh"14minutesagoExited(0)14minutesagobox1 [root@localhost~]#dockerinfo Containers:3 Running:2 Paused:0 Stopped:1 Images:3 ServerVersion:17.09.0-ce StorageDriver:overlay BackingFilesystem:xfs Supportsd_type:false LoggingDriver:json-file CgroupDriver:cgroupfs Plugins: Volume:local Network:bridgehostmacvlannulloverlay Log:awslogsfluentdgcplogsgelfjournaldjson-filelogentriessplunksyslog Swarm:inactive Runtimes:runc DefaultRuntime:runc InitBinary:docker-init containerdversion:06b9cb35161009dcb7123345749fef02f7cea8e0 runcversion:3f2f8b84a77f73d38244dd690525642a72156c64 initversion:949e6fa SecurityOptions: seccomp Profile:default KernelVersion:3.10.0-327.el7.x86_64 OperatingSystem:CentOSLinux7(Core) OSType:linux Architecture:x86_64 CPUs:1 TotalMemory:993MiB Name:localhost.localdomain ID:6ULL:CFMN:YT7C:4RXZ:2CJ4:26H2:D4Y6:YHUP:SH7L:QLEQ:AWEB:EWTB DockerRootDir:/var/lib/docker DebugMode(client):false DebugMode(server):false Registry:https://index.docker.io/v1/ Experimental:false InsecureRegistries: 127.0.0.0/8 LiveRestoreEnabled:false WARNING:overlay:thebackingxfsfilesystemisformattedwithoutd_typesupport,whichleadstoincorrectbehavior. Reformatthefilesystemwithftype=1toenabled_typesupport. Runningwithoutd_typesupportwillnotbesupportedinfuturereleases. WARNING:bridge-nf-call-iptablesisdisabled WARNING:bridge-nf-call-ip6tablesisdisabled [root@localhost~]#dockerkill9c 9c [root@localhost~]#dockerps-a CONTAINERIDIMAGECOMMANDCREATEDSTATUSPORTSNAMES e84a746ea040busybox"sh"17minutesagoUp17minutesbox3 9c1578a50f0bbusybox"sh"19minutesagoExited(137)3secondsagobox2 4ca3d293206cbusybox"sh"20minutesagoExited(0)20minutesagobox1 [root@localhost~]#dockerstope8 ^[[Ae8 [root@localhost~]#dockerps-a CONTAINERIDIMAGECOMMANDCREATEDSTATUSPORTSNAMES e84a746ea040busybox"sh"19minutesagoExited(137)1secondagobox3 9c1578a50f0bbusybox"sh"21minutesagoExited(137)2minutesagobox2 4ca3d293206cbusybox"sh"22minutesagoExited(0)22minutesagobox1 [root@localhost~]#dockerstarte8 e8 [root@localhost~]#dockerps-a CONTAINERIDIMAGECOMMANDCREATEDSTATUSPORTSNAMES e84a746ea040busybox"sh"22minutesagoUp5secondsbox3 9c1578a50f0bbusybox"sh"24minutesagoExited(137)4minutesagobox2 4ca3d293206cbusybox"sh"24minutesagoExited(0)24minutesagobox1 [root@localhost~]#dockerstart9c 9c [root@localhost~]#dockerps-a CONTAINERIDIMAGECOMMANDCREATEDSTATUSPORTSNAMES e84a746ea040busybox"sh"25minutesagoUp3minutesbox3 9c1578a50f0bbusybox"sh"27minutesagoUp3secondsbox2 4ca3d293206cbusybox"sh"28minutesagoExited(0)28minutesagobox1 [root@localhost~]#dockerrestart9c 9c [root@localhost~]#dockerps-a CONTAINERIDIMAGECOMMANDCREATEDSTATUSPORTSNAMES e84a746ea040busybox"sh"26minutesagoUp4minutesbox3 9c1578a50f0bbusybox"sh"28minutesagoUp7secondsbox2 4ca3d293206cbusybox"sh"28minutesagoExited(0)28minutesagobox1

附加知识:一张图可以了解docker容器的所有状态

部分解释:

用于创建容器的命令

是运行、创建和启动的组合。

创建-创建-开始

示例:

docker创建httpd

OCM硬件信息

Dockerkillid强制关闭容器。

Die,不要强制一个程序退出,否则进程有错误。

dockerpause:暂停容器中的所有进程。

dockerunpause:恢复容器中的所有进程。

以上docker容器状态转换实现是边肖分享的全部内容。希望给大家一个参考,支持我们。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/774138.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-03
下一篇 2022-05-03

发表评论

登录后才能评论

评论列表(0条)

保存