docker容器状态的转换实现

 更新时间:2020年11月19日 10:36  点击:1662

一 docker容器状态转换图

二 实战

[root@localhost ~]# docker info
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 3
Server Version: 17.09.0-ce
Storage Driver: overlay
Backing Filesystem: xfs
Supports d_type: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 06b9cb35161009dcb7123345749fef02f7cea8e0
runc version: 3f2f8b84a77f73d38244dd690525642a72156c64
init version: 949e6fa
Security Options:
seccomp
 Profile: default
Kernel Version: 3.10.0-327.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 993MiB
Name: localhost.localdomain
ID: 6ULL:CFMN:YT7C:4RXZ:2CJ4:26H2:D4Y6:YHUP:SH7L:QLEQ:AWEB:EWTB
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: overlay: the backing xfs filesystem is formatted without d_type support, which leads to incorrect behavior.
     Reformat the filesystem with ftype=1 to enable d_type support.
     Running without d_type support will not be supported in future releases.
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
[root@localhost ~]# docker images
REPOSITORY     TAG         IMAGE ID      CREATED       SIZE
clearlinux     latest       32685d114002    6 days ago     62.5MB
busybox       latest       6ad733544a63    6 days ago     1.13MB
alpine       latest       053cde6e8953    6 days ago     3.96MB
[root@localhost ~]# docker run -d --name box1 busybox
4ca3d293206cd34e449075491679b0cddd619b451cac7a3d20d5b5daaa6095d8
[root@localhost ~]# docker run -itd --name box2 busybox
9c1578a50f0b97d48c7501dda6d6e1c3d8b3d9ed0e37416120f91f5a634fb12f
[root@localhost ~]# docker ps -a
CONTAINER ID    IMAGE        COMMAND       CREATED       STATUS           PORTS        NAMES
9c1578a50f0b    busybox       "sh"        13 seconds ago   Up 11 seconds                  box2
4ca3d293206c    busybox       "sh"        47 seconds ago   Exited (0) 45 seconds ago            box1
[root@localhost ~]# docker run -itd --name box3 busybox
e84a746ea040603aa4db791da77aee2e2502ff5b184e89049a74805671a58ba9
[root@localhost ~]# docker ps -a
CONTAINER ID    IMAGE        COMMAND       CREATED       STATUS           PORTS        NAMES
e84a746ea040    busybox       "sh"        5 seconds ago    Up 4 seconds                  box3
9c1578a50f0b    busybox       "sh"        About a minute ago  Up About a minute               box2
4ca3d293206c    busybox       "sh"        2 minutes ago    Exited (0) 2 minutes ago    
        box1
[root@localhost ~]# docker info
Containers: 3
Running: 2
Paused: 0
Stopped: 1
Images: 3
Server Version: 17.09.0-ce
Storage Driver: overlay
Backing Filesystem: xfs
Supports d_type: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 06b9cb35161009dcb7123345749fef02f7cea8e0
runc version: 3f2f8b84a77f73d38244dd690525642a72156c64
init version: 949e6fa
Security Options:
seccomp
 Profile: default
Kernel Version: 3.10.0-327.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 993MiB
Name: localhost.localdomain
ID: 6ULL:CFMN:YT7C:4RXZ:2CJ4:26H2:D4Y6:YHUP:SH7L:QLEQ:AWEB:EWTB
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: overlay: the backing xfs filesystem is formatted without d_type support, which leads to incorrect behavior.
     Reformat the filesystem with ftype=1 to enable d_type support.
     Running without d_type support will not be supported in future releases.
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
[root@localhost ~]# docker ps -a
CONTAINER ID    IMAGE        COMMAND       CREATED       STATUS           PORTS        NAMES
e84a746ea040    busybox       "sh"        4 minutes ago    Up 4 minutes                  box3
9c1578a50f0b    busybox       "sh"        6 minutes ago    Up 6 minutes                  box2
4ca3d293206c    busybox       "sh"        6 minutes ago    Exited (0) 6 minutes ago            box1
[root@localhost ~]# docker restart 9c
9c
[root@localhost ~]# docker ps -a
CONTAINER ID    IMAGE        COMMAND       CREATED       STATUS           PORTS        NAMES
e84a746ea040    busybox       "sh"        5 minutes ago    Up 5 minutes                  box3
9c1578a50f0b    busybox       "sh"        7 minutes ago    Up 2 seconds                  box2
4ca3d293206c    busybox       "sh"        8 minutes ago    Exited (0) 8 minutes ago            box1
[root@localhost ~]# docker pause 9c
9c
[root@localhost ~]# docker ps -a
CONTAINER ID    IMAGE        COMMAND       CREATED       STATUS           PORTS        NAMES
e84a746ea040    busybox       "sh"        8 minutes ago    Up 8 minutes                  box3
9c1578a50f0b    busybox       "sh"        10 minutes ago   Up 2 minutes (Paused)              box2
4ca3d293206c    busybox       "sh"        10 minutes ago   Exited (0) 10 minutes ago            box1
[root@localhost ~]# docker info
Containers: 3
Running: 1
Paused: 1
Stopped: 1
Images: 3
Server Version: 17.09.0-ce
Storage Driver: overlay
Backing Filesystem: xfs
Supports d_type: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 06b9cb35161009dcb7123345749fef02f7cea8e0
runc version: 3f2f8b84a77f73d38244dd690525642a72156c64
init version: 949e6fa
Security Options:
seccomp
 Profile: default
Kernel Version: 3.10.0-327.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 993MiB
Name: localhost.localdomain
ID: 6ULL:CFMN:YT7C:4RXZ:2CJ4:26H2:D4Y6:YHUP:SH7L:QLEQ:AWEB:EWTB
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: overlay: the backing xfs filesystem is formatted without d_type support, which leads to incorrect behavior.
     Reformat the filesystem with ftype=1 to enable d_type support.
     Running without d_type support will not be supported in future releases.
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
[root@localhost ~]# docker unpause 9c
9c
[root@localhost ~]# docker ps -a
CONTAINER ID    IMAGE        COMMAND       CREATED       STATUS           PORTS        NAMES
e84a746ea040    busybox       "sh"        11 minutes ago   Up 11 minutes                  box3
9c1578a50f0b    busybox       "sh"        13 minutes ago   Up 6 minutes                  box2
4ca3d293206c    busybox       "sh"        14 minutes ago   Exited (0) 14 minutes ago            box1
[root@localhost ~]# docker info
Containers: 3
Running: 2
Paused: 0
Stopped: 1
Images: 3
Server Version: 17.09.0-ce
Storage Driver: overlay
Backing Filesystem: xfs
Supports d_type: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 06b9cb35161009dcb7123345749fef02f7cea8e0
runc version: 3f2f8b84a77f73d38244dd690525642a72156c64
init version: 949e6fa
Security Options:
seccomp
 Profile: default
Kernel Version: 3.10.0-327.el7.x86_64
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 993MiB
Name: localhost.localdomain
ID: 6ULL:CFMN:YT7C:4RXZ:2CJ4:26H2:D4Y6:YHUP:SH7L:QLEQ:AWEB:EWTB
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: overlay: the backing xfs filesystem is formatted without d_type support, which leads to incorrect behavior.
     Reformat the filesystem with ftype=1 to enable d_type support.
     Running without d_type support will not be supported in future releases.
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
[root@localhost ~]# docker kill 9c
9c
[root@localhost ~]# docker ps -a
CONTAINER ID    IMAGE        COMMAND       CREATED       STATUS            PORTS        NAMES
e84a746ea040    busybox       "sh"        17 minutes ago   Up 17 minutes                  box3
9c1578a50f0b    busybox       "sh"        19 minutes ago   Exited (137) 3 seconds ago            box2
4ca3d293206c    busybox       "sh"        20 minutes ago   Exited (0) 20 minutes ago            box1
[root@localhost ~]# docker stop e8
^[[Ae8
[root@localhost ~]# docker ps -a
CONTAINER ID    IMAGE        COMMAND       CREATED       STATUS            PORTS        NAMES
e84a746ea040    busybox       "sh"        19 minutes ago   Exited (137) 1 second ago            box3
9c1578a50f0b    busybox       "sh"        21 minutes ago   Exited (137) 2 minutes ago            box2
4ca3d293206c    busybox       "sh"        22 minutes ago   Exited (0) 22 minutes ago            box1
[root@localhost ~]# docker start e8
e8
[root@localhost ~]# docker ps -a
CONTAINER ID    IMAGE        COMMAND       CREATED       STATUS            PORTS        NAMES
e84a746ea040    busybox       "sh"        22 minutes ago   Up 5 seconds                   box3
9c1578a50f0b    busybox       "sh"        24 minutes ago   Exited (137) 4 minutes ago            box2
4ca3d293206c    busybox       "sh"        24 minutes ago   Exited (0) 24 minutes ago            box1
[root@localhost ~]# docker start 9c
9c
[root@localhost ~]# docker ps -a
CONTAINER ID    IMAGE        COMMAND       CREATED       STATUS           PORTS        NAMES
e84a746ea040    busybox       "sh"        25 minutes ago   Up 3 minutes                  box3
9c1578a50f0b    busybox       "sh"        27 minutes ago   Up 3 seconds                  box2
4ca3d293206c    busybox       "sh"        28 minutes ago   Exited (0) 28 minutes ago            box1
[root@localhost ~]# docker restart 9c
9c
[root@localhost ~]# docker ps -a
CONTAINER ID    IMAGE        COMMAND       CREATED       STATUS           PORTS        NAMES
e84a746ea040    busybox       "sh"        26 minutes ago   Up 4 minutes                  box3
9c1578a50f0b    busybox       "sh"        28 minutes ago   Up 7 seconds                  box2
4ca3d293206c    busybox       "sh"        28 minutes ago   Exited (0) 28 minutes ago            box1

补充知识:一张图看懂docker容器的所有状态

部分解释:

创建容器的命令

run 是create和start的结合

create-created-start

例子:

docker create httpd

OCM硬件信息

docker kill id 强制关闭容器

die某个程序别强制退出,或者进程出错

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

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

以上这篇docker容器状态的转换实现就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持猪先飞。

[!--infotagslink--]

相关文章

  • 分享一段php获取linux服务器状态的代码

    简单的php获取linux服务器状态的代码,不多说-直接上函数:复制代码 代码如下:function get_used_status(){ $fp = popen('top -b -n 2 | grep -E "^(Cpu|Mem|Tasks)"',"r");//获取某一时刻系统cpu和内存使用情况 $rs =...2014-05-31
  • docker 启动elasticsearch镜像,挂载目录后报错的解决

    这篇文章主要介绍了docker 启动 elasticsearch镜像,挂载目录后报错的解决,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-11-20
  • 解决Docker中的error during connect异常情况

    这篇文章主要介绍了解决Docker中的error during connect异常情况,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-11-22
  • docker部署confluence的完整步骤

    这篇文章主要介绍了docker部署confluence的完整步骤,这里的镜像并不是小编自己写的是基于他人打包的文中有详细介绍,需要的朋友可以参考下...2021-06-11
  • 教你如何监控 Java 线程池运行状态的操作(必看)

    这篇文章主要介绍了教你如何监控 Java 线程池运行状态的操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-02-27
  • 解决docker挂载的目录无法读写问题

    这篇文章主要介绍了解决docker挂载的目录无法读写问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-19
  • 教你使用Portainer管理多台Docker容器环境的方法

    这篇文章主要介绍了Portainer管理多台Docker容器环境,本文给大家介绍的非常详细,包括环境准备及管理docker的详细过程,需要的朋友可以参考下...2021-11-11
  • docker swarm外部验证负载均衡时不生效的解决方案

    这篇文章主要介绍了docker swarm外部验证负载均衡时不生效的问题,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2021-04-27
  • docker端口映射及外部无法访问问题

    这篇文章主要介绍了docker端口映射及外部无法访问问题,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-01-19
  • Docker 解决openjdk容器里无法使用JDK的jmap等命令问题

    这篇文章主要介绍了Docker 解决openjdk容器里无法使用JDK的jmap等命令问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-12-04
  • 详解bash中的退出状态机制

    这篇文章主要介绍了详解bash中的退出状态机制,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-07-11
  • Go 容器遍历的实现示例

    Go 语言提供的基础容器,免不了要查询容器中的数据,那么是如何实现遍历的呢?本文将会介绍几种常用容易的遍历及其使用。感兴趣的可以了解一下...2021-06-13
  • 使用rpm安装指定版本docker(1.12.6)的详细步骤

    为了防止安装高版本的docker引发的错误,需要安装1.12.6版本的docker,下面小编给大家带来了使用rpm安装指定版本的docker(1.12.6)的步骤,感兴趣的朋友一起看看吧...2021-08-11
  • 一文搞定Docker安装ElasticSearch的过程

    通过本文可以帮助大家快速学习Docker安装ElasticSearch的过程,本文通过图文并茂的形式给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧...2021-08-31
  • 在docker中执行linux shell命令的操作

    这篇文章主要介绍了在docker中执行linux shell命令的操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-03-30
  • 一条命令重启所有已停止的docker容器操作

    这篇文章主要介绍了一条命令重启所有已停止的docker容器操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-11-20
  • C#判断本地文件是否处于打开状态的方法

    这篇文章主要介绍了C#判断本地文件是否处于打开状态的方法,涉及C#操作文件的技巧,非常具有实用价值,需要的朋友可以参考下...2020-06-25
  • C++ STL关联式容器自定义排序规则的2种方法

    这篇文章主要介绍了C++ STL关联式容器自定义排序规则的2种方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-03-04
  • docker容器与宿主机的数据交互方式总结

    这篇文章主要给大家介绍了关于docker容器与宿主机的数据交互,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-11-09
  • 安装Docker Desktop报错WSL 2 installation is incomplete的问题(解决报错)

    这篇文章主要介绍了安装Docker Desktop报错WSL 2 installation is incomplete的问题,解决方法很简单只需我们自己手动更新一下,我们根据提示去微软官网下载最新版的wsl2安装后即可正常打开,需要的朋友可以参考下...2021-06-13