docker容器状态的转换实现

一 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容器状态的转换实现就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我们。

(0)

相关推荐

  • docker run之后状态总是Exited

    add -it docker run -it -name test -d nginx:latest /bin/bash -d: 后台运行容器,并返回容器ID: -i: 以交互模式运行容器,通常与 -t 同时使用: -t: 为容器重新分配一个伪输入终端,通常与 -i 同时使用: 补充知识:docker-compose 通过sh命令启动nginx 容器自动退出exited with code 0 docker-compose使用的模板文件中有通过entrypoint或者command参数设置容器启动

  • Docker数据卷容器创建及使用方法解析

    数据卷容器是一个专门用来挂载数据卷的容器,该容器主要是供其他容器引用和使用.所谓的数据卷容器,实际上就是一个普通的容器,举例如下: 创建数据卷容器 使用如下方式创建数据卷容器: docker run -itd -v /usr/share/nginx/html/ --name mydata ubuntu 命令执行效果如下图: 引用容器 使用如下命令引用数据卷容器: docker run -itd --volumes-from mydata -p 80:80 --name nginx1 nginx

  • 详解Docker容器数据卷

    是什么 先来看看Docker的理念: 将运用与运行的环境打包形成容器运行,运行可以伴随着容器,但是我们对数据的要求希望是持久化的容器之间希望有可能共享数据 Docker容器产生的数据,如果不通过docker commit生成新的镜像,使得数据做为镜像的一部分保存下来, 那么当容器删除后,数据自然也就没有了. 为了能保存数据在docker中我们使用卷. 一句话:有点类似我们Redis里面的RDB和AOF 能干嘛 卷就是目录或文件,存在于一个或多个容器中,由docker挂载到容器,但不属于联合文件系

  • docker容器状态的转换实现

    一 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: cg

  • docker容器状态转换管理命令实例详解

    目录 前言 一.从镜像启动容器 二.查看容器与日志 三.进入容器内部操作系统 四.停止容器暂停容器 五.启动stopped状态的容器 六.删除容器 七.export与import 八.commit 九.查看容器配置及资源使用情况 总结 前言 docker容器有三种状态运行.停止.暂停,镜像可以创建.运行容器,镜像和容器也可以转换成tar压缩包进行存储.本文为大家介绍容器的状态转换命令及镜像创建运行容器.tar包导入导出相关的命令及使用场景. 结合下文中的命令介绍来理解上面的这张图. 一.从镜像启

  • zabbix监控docker容器状态【推荐】

    前言:前段时间在部署zabbix,有个需求就是需要监控容器的状态 也就是cpu 内存 io的占用,于是就自己写了一个脚本,以及模板,在这里分享一下 嘿嘿 : ) 废话我也就不多说,直接开始 首选,zabbix_agentd 配置  vim /usr/local/zabbix/etc/zabbix_agentd.conf UserParameter=docker.discovery,/usr/local/zabbix/script/docker.py UserParameter=docker.[*

  • docker run -v 挂载数据卷异常,容器状态一直是restarting的解决

    出现的问题: docker run 加上 -v 参数之后,容器就一直是 restarting 状态,去掉 -v 参数就可以正常运行 查找问题: 使用 docker logs 'containerId' 这个containerId,就是docker run之后返回的containerId 可以看到,是权限拒绝的问题 解决问题: docker run时加上参数 :加上--privileged=true 例如: docker run -dit -e MYSQL_ROOT_PASSWORD=123456

  • 如何给一个正在运行的Docker容器动态添加Volume

    之前有人问我Docker容器启动之后还能否再挂载卷,考虑mnt命名空间的工作原理,我一开始认为这很难实现.不过现在我认为是它实现的. 简单来说,要想将磁盘卷挂载到正在运行的容器上,我们需要: 使用nsenter将包含这个磁盘卷的整个文件系统mount到临时挂载点上: 从我们想当作磁盘卷使用的特定文件夹中创建绑定挂载(bind mount)到这个磁盘卷的位置: umount第一步创建的临时挂载点. 注意事项 在下面的示例中,我故意包含了$符号来表示这是Shell命令行提示符,以帮助大家区分哪些是你

  • Docker 容器监控原理及 cAdvisor的安装与使用说明

    生产环境中监控容器的运行状况十分重要,通过监控我们可以随时掌握容器的运行状态,做到线上隐患和问题早发现,早解决. 所以今天我就和你分享关于容器监控的知识(原理及工具 cAdvisor). 虽然传统的物理机和虚拟机监控已经有了比较成熟的监控方案,但是容器的监控面临着更大的挑战,因为容器的行为和本质与传统的虚拟机是不一样的,总的来说,容器具有以下特性: 容器是短期存活的,并且可以动态调度 容器的本质是进程,而不是一个完整操作系统 由于容器非常轻量,容器的创建和销毁也会比传统虚拟机更加频繁 Docke

  • 详解使用export/import导出和导入docker容器

    本文介绍了使用export/import导出和导入docker容器,分享给大家,具体如下: 1.导出容器 如果要导出本地某个容器,可以使用 docker export 命令,导出容器快照到本地文件. $ sudo docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 7691a814370e ubuntu:14.04 "/bin/bash" 36 hours ago Exited (0) 21 hours

  • Docker 容器操作退出后进入解决办法

    在我们对Docker容器操作的时候,有时候会误操作或者其他的原因无意间退出了正在操作的容器,也许你会担忧你在其中的一些操作未保存下来,无须担忧,本文中将会提供各种方法供你参考(我的建议使用最后一种).在本文,我们将讨论五种(4+1)连接Docker容器并与其进行交互的方法.例子中所有的代码都可以在GitHub中找到,你可以亲自对它们进行测试. 1.nsenter 安装 nsenter 工具在 util-Linux 包2.23版本后包含. 如果系统中 util-linux 包没有该命令,可以按照下

  • 在Ubuntu 16.04上用Docker Swarm和DigitalOcean创建一个Docker容器集群的方法

    介绍 Docker Swarm是用于部署Docker主机集群的Docker本地解决方案.您可以使用它来快速部署在本地计算机或受支持的云平台上运行的Docker主机集群. 在Docker 1.12之前,设置和部署Docker主机集群需要使用外部键值存储(如etcd或Consul)来进行服务发现.但是,使用Docker 1.12,不再需要外部发现服务,因为Docker提供了一个内置的键值存储,可以开箱即用. 在本教程中,您将了解如何使用Docker 1.12上的Swarm功能部署一组Docker机器

  • Docker 容器内存监控原理及应用

    Docker 容器内存监控 linux内存监控 要明白docker容器内存是如何计算的,首先要明白linux中内存的相关概念. 使用free命令可以查看当前内存使用情况. [root@localhost ~]$ free total used free shared buffers cached Mem: 264420684 213853512 50567172 71822688 2095364 175733516 -/+ buffers/cache: 36024632 228396052 Sw

随机推荐