• 欢迎访问蜷缩的蜗牛博客 蜷缩的蜗牛
  • 微信搜索: 蜷缩的蜗牛 | 联系站长 kbsonlong@qq.com
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

实例学习ansible系列(12)常用模块之docker

Ansible 蜷缩的蜗牛 8个月前 (01-23) 7次浏览 已收录

知识点:ansible 使用 docker 可以对其进行管理。基本接近 docker-compose 对 docker 的使用支持,非常接近。诸如从 port 的设定到 volume_from 都支持,但是需要 docker-py0.3.0 以上的支持。

使用前提条件

需要使用 docker 的 module 的管理对象节点需要满足如下前提

Package 所需版本
python 2.6 以上
docker-py 0.3.0 以上
docker server 0.10.0 以上

安装 docker-py

一般 python 等基本上无需意识,一般安装了 docker-py 本模块就能支持。

<code class=" hljs ruby">安装步骤
[root<span class="hljs-variable">@host32</span> ~]<span class="hljs-comment"># yum -y python-pip</span>
[root<span class="hljs-variable">@host31</span> ~]<span class="hljs-comment"># yum -y install python-pip</span>
[root<span class="hljs-variable">@host31</span> ~]<span class="hljs-comment"># pip install docker-py</span></code>

使用 docker 模块启动 container

事前确认

<code class=" hljs ruby">[root<span class="hljs-variable">@host31</span> ~]<span class="hljs-comment"># ansible host32 -m shell -a "docker images && docker ps -a"</span>
host32 | <span class="hljs-constant">SUCCESS</span> | rc=<span class="hljs-number">0</span> >>
<span class="hljs-constant">REPOSITORY</span>          <span class="hljs-constant">TAG</span>                 <span class="hljs-constant">IMAGE</span> <span class="hljs-constant">ID</span>            <span class="hljs-constant">CREATED</span>             <span class="hljs-constant">SIZE</span>
docker.io/jenkins   latest              b4974ba62598        <span class="hljs-number">2</span> weeks ago         <span class="hljs-number">741</span> <span class="hljs-constant">MB</span>
<span class="hljs-constant">CONTAINER</span> <span class="hljs-constant">ID</span>        <span class="hljs-constant">IMAGE</span>               <span class="hljs-constant">COMMAND</span>             <span class="hljs-constant">CREATED</span>             <span class="hljs-constant">STATUS</span>              <span class="hljs-constant">PORTS</span>               <span class="hljs-constant">NAMES</span>

[root<span class="hljs-variable">@host31</span> ~]<span class="hljs-comment">#</span></code>

启动 container

<code class=" hljs coffeescript">[root<span class="hljs-property">@host31</span> ~]<span class="hljs-comment"># ansible host32 -m docker -a "image=docker.io/jenkins ports=8080:8080"</span>
host32 | SUCCESS<span class="hljs-function"> =></span> {
    <span class="hljs-string">"ansible_facts"</span>: {
        <span class="hljs-string">"docker_containers"</span>: [
            {
                <span class="hljs-string">"AppArmorProfile"</span>: <span class="hljs-string">""</span>,
                <span class="hljs-string">"Args"</span>: [
                    <span class="hljs-string">"--"</span>,
                    <span class="hljs-string">"/usr/local/bin/jenkins.sh"</span>
                ],
                <span class="hljs-string">"Config"</span>: {
                    <span class="hljs-string">"AttachStderr"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"AttachStdin"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"AttachStdout"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"Cmd"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"Domainname"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"Entrypoint"</span>: [
                        <span class="hljs-string">"/bin/tini"</span>,
                        <span class="hljs-string">"--"</span>,
                        <span class="hljs-string">"/usr/local/bin/jenkins.sh"</span>
                    ],
                    <span class="hljs-string">"Env"</span>: [
                        <span class="hljs-string">"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"</span>,
                        <span class="hljs-string">"LANG=C.UTF-8"</span>,
                        <span class="hljs-string">"JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64"</span>,
                        <span class="hljs-string">"JAVA_VERSION=8u91"</span>,
                        <span class="hljs-string">"JAVA_DEBIAN_VERSION=8u91-b14-1~bpo8+1"</span>,
                        <span class="hljs-string">"CA_CERTIFICATES_JAVA_VERSION=20140324"</span>,
                        <span class="hljs-string">"JENKINS_HOME=/var/jenkins_home"</span>,
                        <span class="hljs-string">"JENKINS_SLAVE_AGENT_PORT=50000"</span>,
                        <span class="hljs-string">"TINI_VERSION=0.9.0"</span>,
                        <span class="hljs-string">"TINI_SHA=fa23d1e20732501c3bb8eeeca423c89ac80ed452"</span>,
                        <span class="hljs-string">"JENKINS_VERSION=2.7.1"</span>,
                        <span class="hljs-string">"JENKINS_SHA=12d820574c8f586f7d441986dd53bcfe72b95453"</span>,
                        <span class="hljs-string">"JENKINS_UC=https://updates.jenkins.io"</span>,
                        <span class="hljs-string">"COPY_REFERENCE_FILE_LOG=/var/jenkins_home/copy_reference_file.log"</span>
                    ],
                    <span class="hljs-string">"ExposedPorts"</span>: {
                        <span class="hljs-string">"50000/tcp"</span>: {},
                        <span class="hljs-string">"8080/tcp"</span>: {}
                    },
                    <span class="hljs-string">"Hostname"</span>: <span class="hljs-string">"283789b73a8e"</span>,
                    <span class="hljs-string">"Image"</span>: <span class="hljs-string">"docker.io/jenkins"</span>,
                    <span class="hljs-string">"Labels"</span>: {},
                    <span class="hljs-string">"OnBuild"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"OpenStdin"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"StdinOnce"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"Tty"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"User"</span>: <span class="hljs-string">"jenkins"</span>,
                    <span class="hljs-string">"Volumes"</span>: {
                        <span class="hljs-string">"/var/jenkins_home"</span>: {}
                    },
                    <span class="hljs-string">"WorkingDir"</span>: <span class="hljs-string">""</span>
                },
                <span class="hljs-string">"Created"</span>: <span class="hljs-string">"2016-07-31T03:03:38.350849615Z"</span>,
                <span class="hljs-string">"Driver"</span>: <span class="hljs-string">"devicemapper"</span>,
                <span class="hljs-string">"ExecIDs"</span>: <span class="hljs-literal">null</span>,
                <span class="hljs-string">"GraphDriver"</span>: {
                    <span class="hljs-string">"Data"</span>: {
                        <span class="hljs-string">"DeviceId"</span>: <span class="hljs-string">"25"</span>,
                        <span class="hljs-string">"DeviceName"</span>: <span class="hljs-string">"docker-253:0-19943542-b5917ff17a3050352a5cf430fa1449362166da5142d76e931553119acb600654"</span>,
                        <span class="hljs-string">"DeviceSize"</span>: <span class="hljs-string">"10737418240"</span>
                    },
                    <span class="hljs-string">"Name"</span>: <span class="hljs-string">"devicemapper"</span>
                },
                <span class="hljs-string">"HostConfig"</span>: {
                    <span class="hljs-string">"Binds"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"BlkioDeviceReadBps"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"BlkioDeviceReadIOps"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"BlkioDeviceWriteBps"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"BlkioDeviceWriteIOps"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"BlkioWeight"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"BlkioWeightDevice"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"CapAdd"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"CapDrop"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"CgroupParent"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"ConsoleSize"</span>: [
                        <span class="hljs-number">0</span>,
                        <span class="hljs-number">0</span>
                    ],
                    <span class="hljs-string">"ContainerIDFile"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"CpuPeriod"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"CpuQuota"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"CpuShares"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"CpusetCpus"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"CpusetMems"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"Devices"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"Dns"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"DnsOptions"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"DnsSearch"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"ExtraHosts"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"GroupAdd"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"IpcMode"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"Isolation"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"KernelMemory"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"Links"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"LogConfig"</span>: {
                        <span class="hljs-string">"Config"</span>: {},
                        <span class="hljs-string">"Type"</span>: <span class="hljs-string">"journald"</span>
                    },
                    <span class="hljs-string">"Memory"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"MemoryReservation"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"MemorySwap"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"MemorySwappiness"</span>: -<span class="hljs-number">1</span>,
                    <span class="hljs-string">"NetworkMode"</span>: <span class="hljs-string">"default"</span>,
                    <span class="hljs-string">"OomKillDisable"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"OomScoreAdj"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"PidMode"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"PidsLimit"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"PortBindings"</span>: {
                        <span class="hljs-string">"8080/tcp"</span>: [
                            {
                                <span class="hljs-string">"HostIp"</span>: <span class="hljs-string">"0.0.0.0"</span>,
                                <span class="hljs-string">"HostPort"</span>: <span class="hljs-string">"8080"</span>
                            }
                        ]
                    },
                    <span class="hljs-string">"Privileged"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"PublishAllPorts"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"ReadonlyRootfs"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"RestartPolicy"</span>: {
                        <span class="hljs-string">"MaximumRetryCount"</span>: <span class="hljs-number">0</span>,
                        <span class="hljs-string">"Name"</span>: <span class="hljs-string">""</span>
                    },
                    <span class="hljs-string">"SecurityOpt"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"ShmSize"</span>: <span class="hljs-number">67108864</span>,
                    <span class="hljs-string">"UTSMode"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"Ulimits"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"VolumeDriver"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"VolumesFrom"</span>: <span class="hljs-literal">null</span>
                },
                <span class="hljs-string">"HostnamePath"</span>: <span class="hljs-string">"/var/lib/docker/containers/283789b73a8e044943f5f6b719c6b769fc72b4c83902b908a8444cc77f85c955/hostname"</span>,
                <span class="hljs-string">"HostsPath"</span>: <span class="hljs-string">"/var/lib/docker/containers/283789b73a8e044943f5f6b719c6b769fc72b4c83902b908a8444cc77f85c955/hosts"</span>,
                <span class="hljs-string">"Id"</span>: <span class="hljs-string">"283789b73a8e044943f5f6b719c6b769fc72b4c83902b908a8444cc77f85c955"</span>,
                <span class="hljs-string">"Image"</span>: <span class="hljs-string">"sha256:b4974ba625983cc1250f3399a262d98398b914ff04d2ba360760b81d1c944983"</span>,
                <span class="hljs-string">"LogPath"</span>: <span class="hljs-string">""</span>,
                <span class="hljs-string">"MountLabel"</span>: <span class="hljs-string">"system_u:object_r:svirt_sandbox_file_t:s0:c122,c287"</span>,
                <span class="hljs-string">"Mounts"</span>: [
                    {
                        <span class="hljs-string">"Destination"</span>: <span class="hljs-string">"/var/jenkins_home"</span>,
                        <span class="hljs-string">"Driver"</span>: <span class="hljs-string">"local"</span>,
                        <span class="hljs-string">"Mode"</span>: <span class="hljs-string">""</span>,
                        <span class="hljs-string">"Name"</span>: <span class="hljs-string">"2fdd9acb3d3b497ce12f9584afac3747a4baff991678df15ea3e9bbc97a0411f"</span>,
                        <span class="hljs-string">"Propagation"</span>: <span class="hljs-string">""</span>,
                        <span class="hljs-string">"RW"</span>: <span class="hljs-literal">true</span>,
                        <span class="hljs-string">"Source"</span>: <span class="hljs-string">"/var/lib/docker/volumes/2fdd9acb3d3b497ce12f9584afac3747a4baff991678df15ea3e9bbc97a0411f/_data"</span>
                    }
                ],
                <span class="hljs-string">"Name"</span>: <span class="hljs-string">"/goofy_spence"</span>,
                <span class="hljs-string">"NetworkSettings"</span>: {
                    <span class="hljs-string">"Bridge"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"EndpointID"</span>: <span class="hljs-string">"45fde805822822b90f6e8fabe865ae0ab7faa39ca9e1624e6dea614d4403a6e8"</span>,
                    <span class="hljs-string">"Gateway"</span>: <span class="hljs-string">"172.16.96.1"</span>,
                    <span class="hljs-string">"GlobalIPv6Address"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"GlobalIPv6PrefixLen"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"HairpinMode"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"IPAddress"</span>: <span class="hljs-string">"172.16.96.2"</span>,
                    <span class="hljs-string">"IPPrefixLen"</span>: <span class="hljs-number">24</span>,
                    <span class="hljs-string">"IPv6Gateway"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"LinkLocalIPv6Address"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"LinkLocalIPv6PrefixLen"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"MacAddress"</span>: <span class="hljs-string">"02:42:ac:10:60:02"</span>,
                    <span class="hljs-string">"Networks"</span>: {
                        <span class="hljs-string">"bridge"</span>: {
                            <span class="hljs-string">"Aliases"</span>: <span class="hljs-literal">null</span>,
                            <span class="hljs-string">"EndpointID"</span>: <span class="hljs-string">"45fde805822822b90f6e8fabe865ae0ab7faa39ca9e1624e6dea614d4403a6e8"</span>,
                            <span class="hljs-string">"Gateway"</span>: <span class="hljs-string">"172.16.96.1"</span>,
                            <span class="hljs-string">"GlobalIPv6Address"</span>: <span class="hljs-string">""</span>,
                            <span class="hljs-string">"GlobalIPv6PrefixLen"</span>: <span class="hljs-number">0</span>,
                            <span class="hljs-string">"IPAMConfig"</span>: <span class="hljs-literal">null</span>,
                            <span class="hljs-string">"IPAddress"</span>: <span class="hljs-string">"172.16.96.2"</span>,
                            <span class="hljs-string">"IPPrefixLen"</span>: <span class="hljs-number">24</span>,
                            <span class="hljs-string">"IPv6Gateway"</span>: <span class="hljs-string">""</span>,
                            <span class="hljs-string">"Links"</span>: <span class="hljs-literal">null</span>,
                            <span class="hljs-string">"MacAddress"</span>: <span class="hljs-string">"02:42:ac:10:60:02"</span>,
                            <span class="hljs-string">"NetworkID"</span>: <span class="hljs-string">"320ec600e4605955d8d83b717a5177b2eaf81c97615af4dc606cba34f3952b29"</span>
                        }
                    },
                    <span class="hljs-string">"Ports"</span>: {
                        <span class="hljs-string">"50000/tcp"</span>: <span class="hljs-literal">null</span>,
                        <span class="hljs-string">"8080/tcp"</span>: [
                            {
                                <span class="hljs-string">"HostIp"</span>: <span class="hljs-string">"0.0.0.0"</span>,
                                <span class="hljs-string">"HostPort"</span>: <span class="hljs-string">"8080"</span>
                            }
                        ]
                    },
                    <span class="hljs-string">"SandboxID"</span>: <span class="hljs-string">"8ebecd9887e411a4294a57e50da61c0e669dddaf193cebc0c2fe0c5a523df0e2"</span>,
                    <span class="hljs-string">"SandboxKey"</span>: <span class="hljs-string">"/var/run/docker/netns/8ebecd9887e4"</span>,
                    <span class="hljs-string">"SecondaryIPAddresses"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"SecondaryIPv6Addresses"</span>: <span class="hljs-literal">null</span>
                },
                <span class="hljs-string">"Path"</span>: <span class="hljs-string">"/bin/tini"</span>,
                <span class="hljs-string">"ProcessLabel"</span>: <span class="hljs-string">"system_u:system_r:svirt_lxc_net_t:s0:c122,c287"</span>,
                <span class="hljs-string">"ResolvConfPath"</span>: <span class="hljs-string">"/var/lib/docker/containers/283789b73a8e044943f5f6b719c6b769fc72b4c83902b908a8444cc77f85c955/resolv.conf"</span>,
                <span class="hljs-string">"RestartCount"</span>: <span class="hljs-number">0</span>,
                <span class="hljs-string">"State"</span>: {
                    <span class="hljs-string">"Dead"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"Error"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"ExitCode"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"FinishedAt"</span>: <span class="hljs-string">"0001-01-01T00:00:00Z"</span>,
                    <span class="hljs-string">"OOMKilled"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"Paused"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"Pid"</span>: <span class="hljs-number">30604</span>,
                    <span class="hljs-string">"Restarting"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"Running"</span>: <span class="hljs-literal">true</span>,
                    <span class="hljs-string">"StartedAt"</span>: <span class="hljs-string">"2016-07-31T03:03:39.630193596Z"</span>,
                    <span class="hljs-string">"Status"</span>: <span class="hljs-string">"running"</span>
                }
            }
        ]
    },
    <span class="hljs-string">"changed"</span>: <span class="hljs-literal">true</span>,
    <span class="hljs-string">"msg"</span>: <span class="hljs-string">"started 1 container, created 1 container."</span>,
    <span class="hljs-string">"reload_reasons"</span>: <span class="hljs-literal">null</span>,
    <span class="hljs-string">"summary"</span>: {
        <span class="hljs-string">"created"</span>: <span class="hljs-number">1</span>,
        <span class="hljs-string">"killed"</span>: <span class="hljs-number">0</span>,
        <span class="hljs-string">"pulled"</span>: <span class="hljs-number">0</span>,
        <span class="hljs-string">"removed"</span>: <span class="hljs-number">0</span>,
        <span class="hljs-string">"restarted"</span>: <span class="hljs-number">0</span>,
        <span class="hljs-string">"started"</span>: <span class="hljs-number">1</span>,
        <span class="hljs-string">"stopped"</span>: <span class="hljs-number">0</span>
    }
}
[root<span class="hljs-property">@host31</span> ~]<span class="hljs-comment">#</span></code>

确认结果

<code class=" hljs ruby">[root<span class="hljs-variable">@host31</span> ~]<span class="hljs-comment"># ansible host32 -m shell -a "docker images && docker ps -a"</span>
host32 | <span class="hljs-constant">SUCCESS</span> | rc=<span class="hljs-number">0</span> >>
<span class="hljs-constant">REPOSITORY</span>          <span class="hljs-constant">TAG</span>                 <span class="hljs-constant">IMAGE</span> <span class="hljs-constant">ID</span>            <span class="hljs-constant">CREATED</span>             <span class="hljs-constant">SIZE</span>
docker.io/jenkins   latest              b4974ba62598        <span class="hljs-number">2</span> weeks ago         <span class="hljs-number">741</span> <span class="hljs-constant">MB</span>
<span class="hljs-constant">CONTAINER</span> <span class="hljs-constant">ID</span>        <span class="hljs-constant">IMAGE</span>               <span class="hljs-constant">COMMAND</span>                  <span class="hljs-constant">CREATED</span>             <span class="hljs-constant">STATUS</span>              <span class="hljs-constant">PORTS</span>                               <span class="hljs-constant">NAMES</span>
<span class="hljs-number">283789</span>b73a8e        docker.io/jenkins   <span class="hljs-string">"/bin/tini -- /usr/lo"</span>   <span class="hljs-number">3</span> minutes ago       <span class="hljs-constant">Up</span> <span class="hljs-number">3</span> minutes        <span class="hljs-number">0</span>.<span class="hljs-number">0</span>.<span class="hljs-number">0</span>.<span class="hljs-number">0</span><span class="hljs-symbol">:</span><span class="hljs-number">8080</span>-><span class="hljs-number">8080</span>/tcp, <span class="hljs-number">50000</span>/tcp   goofy_spence

[root<span class="hljs-variable">@host31</span> ~]<span class="hljs-comment">#</span></code>

jenkins login

停止 container

实现 docker stop 的操作

<code class=" hljs coffeescript">[root<span class="hljs-property">@host31</span> ~]<span class="hljs-comment"># ansible host32 -m docker -a "image=docker.io/jenkins state=stopped"</span>
host32 | SUCCESS<span class="hljs-function"> =></span> {
    <span class="hljs-string">"ansible_facts"</span>: {
        <span class="hljs-string">"docker_containers"</span>: [
            {
                <span class="hljs-string">"AppArmorProfile"</span>: <span class="hljs-string">""</span>,
                <span class="hljs-string">"Args"</span>: [
                    <span class="hljs-string">"--"</span>,
                    <span class="hljs-string">"/usr/local/bin/jenkins.sh"</span>
                ],
                <span class="hljs-string">"Config"</span>: {
                    <span class="hljs-string">"AttachStderr"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"AttachStdin"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"AttachStdout"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"Cmd"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"Domainname"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"Entrypoint"</span>: [
                        <span class="hljs-string">"/bin/tini"</span>,
                        <span class="hljs-string">"--"</span>,
                        <span class="hljs-string">"/usr/local/bin/jenkins.sh"</span>
                    ],
                    <span class="hljs-string">"Env"</span>: [
                        <span class="hljs-string">"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"</span>,
                        <span class="hljs-string">"LANG=C.UTF-8"</span>,
                        <span class="hljs-string">"JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64"</span>,
                        <span class="hljs-string">"JAVA_VERSION=8u91"</span>,
                        <span class="hljs-string">"JAVA_DEBIAN_VERSION=8u91-b14-1~bpo8+1"</span>,
                        <span class="hljs-string">"CA_CERTIFICATES_JAVA_VERSION=20140324"</span>,
                        <span class="hljs-string">"JENKINS_HOME=/var/jenkins_home"</span>,
                        <span class="hljs-string">"JENKINS_SLAVE_AGENT_PORT=50000"</span>,
                        <span class="hljs-string">"TINI_VERSION=0.9.0"</span>,
                        <span class="hljs-string">"TINI_SHA=fa23d1e20732501c3bb8eeeca423c89ac80ed452"</span>,
                        <span class="hljs-string">"JENKINS_VERSION=2.7.1"</span>,
                        <span class="hljs-string">"JENKINS_SHA=12d820574c8f586f7d441986dd53bcfe72b95453"</span>,
                        <span class="hljs-string">"JENKINS_UC=https://updates.jenkins.io"</span>,
                        <span class="hljs-string">"COPY_REFERENCE_FILE_LOG=/var/jenkins_home/copy_reference_file.log"</span>
                    ],
                    <span class="hljs-string">"ExposedPorts"</span>: {
                        <span class="hljs-string">"50000/tcp"</span>: {},
                        <span class="hljs-string">"8080/tcp"</span>: {}
                    },
                    <span class="hljs-string">"Hostname"</span>: <span class="hljs-string">"283789b73a8e"</span>,
                    <span class="hljs-string">"Image"</span>: <span class="hljs-string">"docker.io/jenkins"</span>,
                    <span class="hljs-string">"Labels"</span>: {},
                    <span class="hljs-string">"OnBuild"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"OpenStdin"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"StdinOnce"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"Tty"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"User"</span>: <span class="hljs-string">"jenkins"</span>,
                    <span class="hljs-string">"Volumes"</span>: {
                        <span class="hljs-string">"/var/jenkins_home"</span>: {}
                    },
                    <span class="hljs-string">"WorkingDir"</span>: <span class="hljs-string">""</span>
                },
                <span class="hljs-string">"Created"</span>: <span class="hljs-string">"2016-07-31T03:03:38.350849615Z"</span>,
                <span class="hljs-string">"Driver"</span>: <span class="hljs-string">"devicemapper"</span>,
                <span class="hljs-string">"ExecIDs"</span>: <span class="hljs-literal">null</span>,
                <span class="hljs-string">"GraphDriver"</span>: {
                    <span class="hljs-string">"Data"</span>: {
                        <span class="hljs-string">"DeviceId"</span>: <span class="hljs-string">"25"</span>,
                        <span class="hljs-string">"DeviceName"</span>: <span class="hljs-string">"docker-253:0-19943542-b5917ff17a3050352a5cf430fa1449362166da5142d76e931553119acb600654"</span>,
                        <span class="hljs-string">"DeviceSize"</span>: <span class="hljs-string">"10737418240"</span>
                    },
                    <span class="hljs-string">"Name"</span>: <span class="hljs-string">"devicemapper"</span>
                },
                <span class="hljs-string">"HostConfig"</span>: {
                    <span class="hljs-string">"Binds"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"BlkioDeviceReadBps"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"BlkioDeviceReadIOps"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"BlkioDeviceWriteBps"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"BlkioDeviceWriteIOps"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"BlkioWeight"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"BlkioWeightDevice"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"CapAdd"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"CapDrop"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"CgroupParent"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"ConsoleSize"</span>: [
                        <span class="hljs-number">0</span>,
                        <span class="hljs-number">0</span>
                    ],
                    <span class="hljs-string">"ContainerIDFile"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"CpuPeriod"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"CpuQuota"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"CpuShares"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"CpusetCpus"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"CpusetMems"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"Devices"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"Dns"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"DnsOptions"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"DnsSearch"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"ExtraHosts"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"GroupAdd"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"IpcMode"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"Isolation"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"KernelMemory"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"Links"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"LogConfig"</span>: {
                        <span class="hljs-string">"Config"</span>: {},
                        <span class="hljs-string">"Type"</span>: <span class="hljs-string">"journald"</span>
                    },
                    <span class="hljs-string">"Memory"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"MemoryReservation"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"MemorySwap"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"MemorySwappiness"</span>: -<span class="hljs-number">1</span>,
                    <span class="hljs-string">"NetworkMode"</span>: <span class="hljs-string">"default"</span>,
                    <span class="hljs-string">"OomKillDisable"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"OomScoreAdj"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"PidMode"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"PidsLimit"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"PortBindings"</span>: {
                        <span class="hljs-string">"8080/tcp"</span>: [
                            {
                                <span class="hljs-string">"HostIp"</span>: <span class="hljs-string">"0.0.0.0"</span>,
                                <span class="hljs-string">"HostPort"</span>: <span class="hljs-string">"8080"</span>
                            }
                        ]
                    },
                    <span class="hljs-string">"Privileged"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"PublishAllPorts"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"ReadonlyRootfs"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"RestartPolicy"</span>: {
                        <span class="hljs-string">"MaximumRetryCount"</span>: <span class="hljs-number">0</span>,
                        <span class="hljs-string">"Name"</span>: <span class="hljs-string">""</span>
                    },
                    <span class="hljs-string">"SecurityOpt"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"ShmSize"</span>: <span class="hljs-number">67108864</span>,
                    <span class="hljs-string">"UTSMode"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"Ulimits"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"VolumeDriver"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"VolumesFrom"</span>: <span class="hljs-literal">null</span>
                },
                <span class="hljs-string">"HostnamePath"</span>: <span class="hljs-string">"/var/lib/docker/containers/283789b73a8e044943f5f6b719c6b769fc72b4c83902b908a8444cc77f85c955/hostname"</span>,
                <span class="hljs-string">"HostsPath"</span>: <span class="hljs-string">"/var/lib/docker/containers/283789b73a8e044943f5f6b719c6b769fc72b4c83902b908a8444cc77f85c955/hosts"</span>,
                <span class="hljs-string">"Id"</span>: <span class="hljs-string">"283789b73a8e044943f5f6b719c6b769fc72b4c83902b908a8444cc77f85c955"</span>,
                <span class="hljs-string">"Image"</span>: <span class="hljs-string">"sha256:b4974ba625983cc1250f3399a262d98398b914ff04d2ba360760b81d1c944983"</span>,
                <span class="hljs-string">"LogPath"</span>: <span class="hljs-string">""</span>,
                <span class="hljs-string">"MountLabel"</span>: <span class="hljs-string">"system_u:object_r:svirt_sandbox_file_t:s0:c122,c287"</span>,
                <span class="hljs-string">"Mounts"</span>: [
                    {
                        <span class="hljs-string">"Destination"</span>: <span class="hljs-string">"/var/jenkins_home"</span>,
                        <span class="hljs-string">"Driver"</span>: <span class="hljs-string">"local"</span>,
                        <span class="hljs-string">"Mode"</span>: <span class="hljs-string">""</span>,
                        <span class="hljs-string">"Name"</span>: <span class="hljs-string">"2fdd9acb3d3b497ce12f9584afac3747a4baff991678df15ea3e9bbc97a0411f"</span>,
                        <span class="hljs-string">"Propagation"</span>: <span class="hljs-string">""</span>,
                        <span class="hljs-string">"RW"</span>: <span class="hljs-literal">true</span>,
                        <span class="hljs-string">"Source"</span>: <span class="hljs-string">"/var/lib/docker/volumes/2fdd9acb3d3b497ce12f9584afac3747a4baff991678df15ea3e9bbc97a0411f/_data"</span>
                    }
                ],
                <span class="hljs-string">"Name"</span>: <span class="hljs-string">"/goofy_spence"</span>,
                <span class="hljs-string">"NetworkSettings"</span>: {
                    <span class="hljs-string">"Bridge"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"EndpointID"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"Gateway"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"GlobalIPv6Address"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"GlobalIPv6PrefixLen"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"HairpinMode"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"IPAddress"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"IPPrefixLen"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"IPv6Gateway"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"LinkLocalIPv6Address"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"LinkLocalIPv6PrefixLen"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"MacAddress"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"Networks"</span>: {
                        <span class="hljs-string">"bridge"</span>: {
                            <span class="hljs-string">"Aliases"</span>: <span class="hljs-literal">null</span>,
                            <span class="hljs-string">"EndpointID"</span>: <span class="hljs-string">""</span>,
                            <span class="hljs-string">"Gateway"</span>: <span class="hljs-string">""</span>,
                            <span class="hljs-string">"GlobalIPv6Address"</span>: <span class="hljs-string">""</span>,
                            <span class="hljs-string">"GlobalIPv6PrefixLen"</span>: <span class="hljs-number">0</span>,
                            <span class="hljs-string">"IPAMConfig"</span>: <span class="hljs-literal">null</span>,
                            <span class="hljs-string">"IPAddress"</span>: <span class="hljs-string">""</span>,
                            <span class="hljs-string">"IPPrefixLen"</span>: <span class="hljs-number">0</span>,
                            <span class="hljs-string">"IPv6Gateway"</span>: <span class="hljs-string">""</span>,
                            <span class="hljs-string">"Links"</span>: <span class="hljs-literal">null</span>,
                            <span class="hljs-string">"MacAddress"</span>: <span class="hljs-string">""</span>,
                            <span class="hljs-string">"NetworkID"</span>: <span class="hljs-string">"320ec600e4605955d8d83b717a5177b2eaf81c97615af4dc606cba34f3952b29"</span>
                        }
                    },
                    <span class="hljs-string">"Ports"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"SandboxID"</span>: <span class="hljs-string">"8ebecd9887e411a4294a57e50da61c0e669dddaf193cebc0c2fe0c5a523df0e2"</span>,
                    <span class="hljs-string">"SandboxKey"</span>: <span class="hljs-string">"/var/run/docker/netns/8ebecd9887e4"</span>,
                    <span class="hljs-string">"SecondaryIPAddresses"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"SecondaryIPv6Addresses"</span>: <span class="hljs-literal">null</span>
                },
                <span class="hljs-string">"Path"</span>: <span class="hljs-string">"/bin/tini"</span>,
                <span class="hljs-string">"ProcessLabel"</span>: <span class="hljs-string">"system_u:system_r:svirt_lxc_net_t:s0:c122,c287"</span>,
                <span class="hljs-string">"ResolvConfPath"</span>: <span class="hljs-string">"/var/lib/docker/containers/283789b73a8e044943f5f6b719c6b769fc72b4c83902b908a8444cc77f85c955/resolv.conf"</span>,
                <span class="hljs-string">"RestartCount"</span>: <span class="hljs-number">0</span>,
                <span class="hljs-string">"State"</span>: {
                    <span class="hljs-string">"Dead"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"Error"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"ExitCode"</span>: <span class="hljs-number">143</span>,
                    <span class="hljs-string">"FinishedAt"</span>: <span class="hljs-string">"2016-07-31T03:10:05.113884817Z"</span>,
                    <span class="hljs-string">"OOMKilled"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"Paused"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"Pid"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"Restarting"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"Running"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"StartedAt"</span>: <span class="hljs-string">"2016-07-31T03:03:39.630193596Z"</span>,
                    <span class="hljs-string">"Status"</span>: <span class="hljs-string">"exited"</span>
                }
            }
        ]
    },
    <span class="hljs-string">"changed"</span>: <span class="hljs-literal">true</span>,
    <span class="hljs-string">"msg"</span>: <span class="hljs-string">"stopped 1 container."</span>,
    <span class="hljs-string">"reload_reasons"</span>: <span class="hljs-literal">null</span>,
    <span class="hljs-string">"summary"</span>: {
        <span class="hljs-string">"created"</span>: <span class="hljs-number">0</span>,
        <span class="hljs-string">"killed"</span>: <span class="hljs-number">0</span>,
        <span class="hljs-string">"pulled"</span>: <span class="hljs-number">0</span>,
        <span class="hljs-string">"removed"</span>: <span class="hljs-number">0</span>,
        <span class="hljs-string">"restarted"</span>: <span class="hljs-number">0</span>,
        <span class="hljs-string">"started"</span>: <span class="hljs-number">0</span>,
        <span class="hljs-string">"stopped"</span>: <span class="hljs-number">1</span>
    }
}
[root<span class="hljs-property">@host31</span> ~]<span class="hljs-comment">#</span></code>

停止确认

<code class=" hljs ruby">[root<span class="hljs-variable">@host31</span> ~]<span class="hljs-comment"># ansible host32 -m shell -a "docker images && docker ps"</span>
host32 | <span class="hljs-constant">SUCCESS</span> | rc=<span class="hljs-number">0</span> >>
<span class="hljs-constant">REPOSITORY</span>          <span class="hljs-constant">TAG</span>                 <span class="hljs-constant">IMAGE</span> <span class="hljs-constant">ID</span>            <span class="hljs-constant">CREATED</span>             <span class="hljs-constant">SIZE</span>
docker.io/jenkins   latest              b4974ba62598        <span class="hljs-number">2</span> weeks ago         <span class="hljs-number">741</span> <span class="hljs-constant">MB</span>
<span class="hljs-constant">CONTAINER</span> <span class="hljs-constant">ID</span>        <span class="hljs-constant">IMAGE</span>               <span class="hljs-constant">COMMAND</span>             <span class="hljs-constant">CREATED</span>             <span class="hljs-constant">STATUS</span>              <span class="hljs-constant">PORTS</span>               <span class="hljs-constant">NAMES</span>

[root<span class="hljs-variable">@host31</span> ~]<span class="hljs-comment">#</span>
[root<span class="hljs-variable">@host31</span> ~]<span class="hljs-comment"># ansible host32 -m shell -a "docker ps -a"</span>
host32 | <span class="hljs-constant">SUCCESS</span> | rc=<span class="hljs-number">0</span> >>
<span class="hljs-constant">CONTAINER</span> <span class="hljs-constant">ID</span>        <span class="hljs-constant">IMAGE</span>               <span class="hljs-constant">COMMAND</span>                  <span class="hljs-constant">CREATED</span>             <span class="hljs-constant">STATUS</span>                            <span class="hljs-constant">PORTS</span>               <span class="hljs-constant">NAMES</span>
<span class="hljs-number">283789</span>b73a8e        docker.io/jenkins   <span class="hljs-string">"/bin/tini -- /usr/lo"</span>   <span class="hljs-number">7</span> minutes ago       <span class="hljs-constant">Exited</span> (<span class="hljs-number">143</span>) <span class="hljs-constant">About</span> a minute ago                       goofy_spence

[root<span class="hljs-variable">@host31</span> ~]<span class="hljs-comment">#</span></code>

删除 container

实现 docker rm 的操作

<code class=" hljs coffeescript">[root<span class="hljs-property">@host31</span> ~]<span class="hljs-comment"># ansible host32 -m shell -a "docker ps -a"</span>
host32 | SUCCESS | rc=<span class="hljs-number">0</span> >>
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                       PORTS               NAMES
<span class="hljs-number">283789</span>b73a8e        docker.io/jenkins   <span class="hljs-string">"/bin/tini -- /usr/lo"</span>   <span class="hljs-number">8</span> minutes ago       Exited (<span class="hljs-number">143</span>) <span class="hljs-number">2</span> minutes ago                       goofy_spence

[root<span class="hljs-property">@host31</span> ~]<span class="hljs-comment">#</span>
[root<span class="hljs-property">@host31</span> ~]<span class="hljs-comment"># ansible host32 -m docker -a "image=docker.io/jenkins state=absent"</span>
host32 | SUCCESS<span class="hljs-function"> =></span> {
    <span class="hljs-string">"ansible_facts"</span>: {
        <span class="hljs-string">"docker_containers"</span>: [
            {
                <span class="hljs-string">"AppArmorProfile"</span>: <span class="hljs-string">""</span>,
                <span class="hljs-string">"Args"</span>: [
                    <span class="hljs-string">"--"</span>,
                    <span class="hljs-string">"/usr/local/bin/jenkins.sh"</span>
                ],
                <span class="hljs-string">"Config"</span>: {
                    <span class="hljs-string">"AttachStderr"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"AttachStdin"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"AttachStdout"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"Cmd"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"Domainname"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"Entrypoint"</span>: [
                        <span class="hljs-string">"/bin/tini"</span>,
                        <span class="hljs-string">"--"</span>,
                        <span class="hljs-string">"/usr/local/bin/jenkins.sh"</span>
                    ],
                    <span class="hljs-string">"Env"</span>: [
                        <span class="hljs-string">"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"</span>,
                        <span class="hljs-string">"LANG=C.UTF-8"</span>,
                        <span class="hljs-string">"JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64"</span>,
                        <span class="hljs-string">"JAVA_VERSION=8u91"</span>,
                        <span class="hljs-string">"JAVA_DEBIAN_VERSION=8u91-b14-1~bpo8+1"</span>,
                        <span class="hljs-string">"CA_CERTIFICATES_JAVA_VERSION=20140324"</span>,
                        <span class="hljs-string">"JENKINS_HOME=/var/jenkins_home"</span>,
                        <span class="hljs-string">"JENKINS_SLAVE_AGENT_PORT=50000"</span>,
                        <span class="hljs-string">"TINI_VERSION=0.9.0"</span>,
                        <span class="hljs-string">"TINI_SHA=fa23d1e20732501c3bb8eeeca423c89ac80ed452"</span>,
                        <span class="hljs-string">"JENKINS_VERSION=2.7.1"</span>,
                        <span class="hljs-string">"JENKINS_SHA=12d820574c8f586f7d441986dd53bcfe72b95453"</span>,
                        <span class="hljs-string">"JENKINS_UC=https://updates.jenkins.io"</span>,
                        <span class="hljs-string">"COPY_REFERENCE_FILE_LOG=/var/jenkins_home/copy_reference_file.log"</span>
                    ],
                    <span class="hljs-string">"ExposedPorts"</span>: {
                        <span class="hljs-string">"50000/tcp"</span>: {},
                        <span class="hljs-string">"8080/tcp"</span>: {}
                    },
                    <span class="hljs-string">"Hostname"</span>: <span class="hljs-string">"283789b73a8e"</span>,
                    <span class="hljs-string">"Image"</span>: <span class="hljs-string">"docker.io/jenkins"</span>,
                    <span class="hljs-string">"Labels"</span>: {},
                    <span class="hljs-string">"OnBuild"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"OpenStdin"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"StdinOnce"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"Tty"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"User"</span>: <span class="hljs-string">"jenkins"</span>,
                    <span class="hljs-string">"Volumes"</span>: {
                        <span class="hljs-string">"/var/jenkins_home"</span>: {}
                    },
                    <span class="hljs-string">"WorkingDir"</span>: <span class="hljs-string">""</span>
                },
                <span class="hljs-string">"Created"</span>: <span class="hljs-string">"2016-07-31T03:03:38.350849615Z"</span>,
                <span class="hljs-string">"Driver"</span>: <span class="hljs-string">"devicemapper"</span>,
                <span class="hljs-string">"ExecIDs"</span>: <span class="hljs-literal">null</span>,
                <span class="hljs-string">"GraphDriver"</span>: {
                    <span class="hljs-string">"Data"</span>: {
                        <span class="hljs-string">"DeviceId"</span>: <span class="hljs-string">"25"</span>,
                        <span class="hljs-string">"DeviceName"</span>: <span class="hljs-string">"docker-253:0-19943542-b5917ff17a3050352a5cf430fa1449362166da5142d76e931553119acb600654"</span>,
                        <span class="hljs-string">"DeviceSize"</span>: <span class="hljs-string">"10737418240"</span>
                    },
                    <span class="hljs-string">"Name"</span>: <span class="hljs-string">"devicemapper"</span>
                },
                <span class="hljs-string">"HostConfig"</span>: {
                    <span class="hljs-string">"Binds"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"BlkioDeviceReadBps"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"BlkioDeviceReadIOps"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"BlkioDeviceWriteBps"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"BlkioDeviceWriteIOps"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"BlkioWeight"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"BlkioWeightDevice"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"CapAdd"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"CapDrop"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"CgroupParent"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"ConsoleSize"</span>: [
                        <span class="hljs-number">0</span>,
                        <span class="hljs-number">0</span>
                    ],
                    <span class="hljs-string">"ContainerIDFile"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"CpuPeriod"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"CpuQuota"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"CpuShares"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"CpusetCpus"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"CpusetMems"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"Devices"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"Dns"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"DnsOptions"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"DnsSearch"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"ExtraHosts"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"GroupAdd"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"IpcMode"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"Isolation"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"KernelMemory"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"Links"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"LogConfig"</span>: {
                        <span class="hljs-string">"Config"</span>: {},
                        <span class="hljs-string">"Type"</span>: <span class="hljs-string">"journald"</span>
                    },
                    <span class="hljs-string">"Memory"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"MemoryReservation"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"MemorySwap"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"MemorySwappiness"</span>: -<span class="hljs-number">1</span>,
                    <span class="hljs-string">"NetworkMode"</span>: <span class="hljs-string">"default"</span>,
                    <span class="hljs-string">"OomKillDisable"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"OomScoreAdj"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"PidMode"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"PidsLimit"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"PortBindings"</span>: {
                        <span class="hljs-string">"8080/tcp"</span>: [
                            {
                                <span class="hljs-string">"HostIp"</span>: <span class="hljs-string">"0.0.0.0"</span>,
                                <span class="hljs-string">"HostPort"</span>: <span class="hljs-string">"8080"</span>
                            }
                        ]
                    },
                    <span class="hljs-string">"Privileged"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"PublishAllPorts"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"ReadonlyRootfs"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"RestartPolicy"</span>: {
                        <span class="hljs-string">"MaximumRetryCount"</span>: <span class="hljs-number">0</span>,
                        <span class="hljs-string">"Name"</span>: <span class="hljs-string">""</span>
                    },
                    <span class="hljs-string">"SecurityOpt"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"ShmSize"</span>: <span class="hljs-number">67108864</span>,
                    <span class="hljs-string">"UTSMode"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"Ulimits"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"VolumeDriver"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"VolumesFrom"</span>: <span class="hljs-literal">null</span>
                },
                <span class="hljs-string">"HostnamePath"</span>: <span class="hljs-string">"/var/lib/docker/containers/283789b73a8e044943f5f6b719c6b769fc72b4c83902b908a8444cc77f85c955/hostname"</span>,
                <span class="hljs-string">"HostsPath"</span>: <span class="hljs-string">"/var/lib/docker/containers/283789b73a8e044943f5f6b719c6b769fc72b4c83902b908a8444cc77f85c955/hosts"</span>,
                <span class="hljs-string">"Id"</span>: <span class="hljs-string">"283789b73a8e044943f5f6b719c6b769fc72b4c83902b908a8444cc77f85c955"</span>,
                <span class="hljs-string">"Image"</span>: <span class="hljs-string">"sha256:b4974ba625983cc1250f3399a262d98398b914ff04d2ba360760b81d1c944983"</span>,
                <span class="hljs-string">"LogPath"</span>: <span class="hljs-string">""</span>,
                <span class="hljs-string">"MountLabel"</span>: <span class="hljs-string">"system_u:object_r:svirt_sandbox_file_t:s0:c122,c287"</span>,
                <span class="hljs-string">"Mounts"</span>: [
                    {
                        <span class="hljs-string">"Destination"</span>: <span class="hljs-string">"/var/jenkins_home"</span>,
                        <span class="hljs-string">"Driver"</span>: <span class="hljs-string">"local"</span>,
                        <span class="hljs-string">"Mode"</span>: <span class="hljs-string">""</span>,
                        <span class="hljs-string">"Name"</span>: <span class="hljs-string">"2fdd9acb3d3b497ce12f9584afac3747a4baff991678df15ea3e9bbc97a0411f"</span>,
                        <span class="hljs-string">"Propagation"</span>: <span class="hljs-string">""</span>,
                        <span class="hljs-string">"RW"</span>: <span class="hljs-literal">true</span>,
                        <span class="hljs-string">"Source"</span>: <span class="hljs-string">"/var/lib/docker/volumes/2fdd9acb3d3b497ce12f9584afac3747a4baff991678df15ea3e9bbc97a0411f/_data"</span>
                    }
                ],
                <span class="hljs-string">"Name"</span>: <span class="hljs-string">"/goofy_spence"</span>,
                <span class="hljs-string">"NetworkSettings"</span>: {
                    <span class="hljs-string">"Bridge"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"EndpointID"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"Gateway"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"GlobalIPv6Address"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"GlobalIPv6PrefixLen"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"HairpinMode"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"IPAddress"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"IPPrefixLen"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"IPv6Gateway"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"LinkLocalIPv6Address"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"LinkLocalIPv6PrefixLen"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"MacAddress"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"Networks"</span>: {
                        <span class="hljs-string">"bridge"</span>: {
                            <span class="hljs-string">"Aliases"</span>: <span class="hljs-literal">null</span>,
                            <span class="hljs-string">"EndpointID"</span>: <span class="hljs-string">""</span>,
                            <span class="hljs-string">"Gateway"</span>: <span class="hljs-string">""</span>,
                            <span class="hljs-string">"GlobalIPv6Address"</span>: <span class="hljs-string">""</span>,
                            <span class="hljs-string">"GlobalIPv6PrefixLen"</span>: <span class="hljs-number">0</span>,
                            <span class="hljs-string">"IPAMConfig"</span>: <span class="hljs-literal">null</span>,
                            <span class="hljs-string">"IPAddress"</span>: <span class="hljs-string">""</span>,
                            <span class="hljs-string">"IPPrefixLen"</span>: <span class="hljs-number">0</span>,
                            <span class="hljs-string">"IPv6Gateway"</span>: <span class="hljs-string">""</span>,
                            <span class="hljs-string">"Links"</span>: <span class="hljs-literal">null</span>,
                            <span class="hljs-string">"MacAddress"</span>: <span class="hljs-string">""</span>,
                            <span class="hljs-string">"NetworkID"</span>: <span class="hljs-string">"320ec600e4605955d8d83b717a5177b2eaf81c97615af4dc606cba34f3952b29"</span>
                        }
                    },
                    <span class="hljs-string">"Ports"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"SandboxID"</span>: <span class="hljs-string">"8ebecd9887e411a4294a57e50da61c0e669dddaf193cebc0c2fe0c5a523df0e2"</span>,
                    <span class="hljs-string">"SandboxKey"</span>: <span class="hljs-string">"/var/run/docker/netns/8ebecd9887e4"</span>,
                    <span class="hljs-string">"SecondaryIPAddresses"</span>: <span class="hljs-literal">null</span>,
                    <span class="hljs-string">"SecondaryIPv6Addresses"</span>: <span class="hljs-literal">null</span>
                },
                <span class="hljs-string">"Path"</span>: <span class="hljs-string">"/bin/tini"</span>,
                <span class="hljs-string">"ProcessLabel"</span>: <span class="hljs-string">"system_u:system_r:svirt_lxc_net_t:s0:c122,c287"</span>,
                <span class="hljs-string">"ResolvConfPath"</span>: <span class="hljs-string">"/var/lib/docker/containers/283789b73a8e044943f5f6b719c6b769fc72b4c83902b908a8444cc77f85c955/resolv.conf"</span>,
                <span class="hljs-string">"RestartCount"</span>: <span class="hljs-number">0</span>,
                <span class="hljs-string">"State"</span>: {
                    <span class="hljs-string">"Dead"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"Error"</span>: <span class="hljs-string">""</span>,
                    <span class="hljs-string">"ExitCode"</span>: <span class="hljs-number">143</span>,
                    <span class="hljs-string">"FinishedAt"</span>: <span class="hljs-string">"2016-07-31T03:10:05.113884817Z"</span>,
                    <span class="hljs-string">"OOMKilled"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"Paused"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"Pid"</span>: <span class="hljs-number">0</span>,
                    <span class="hljs-string">"Restarting"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"Running"</span>: <span class="hljs-literal">false</span>,
                    <span class="hljs-string">"StartedAt"</span>: <span class="hljs-string">"2016-07-31T03:03:39.630193596Z"</span>,
                    <span class="hljs-string">"Status"</span>: <span class="hljs-string">"exited"</span>
                }
            }
        ]
    },
    <span class="hljs-string">"changed"</span>: <span class="hljs-literal">true</span>,
    <span class="hljs-string">"msg"</span>: <span class="hljs-string">"removed 1 container."</span>,
    <span class="hljs-string">"reload_reasons"</span>: <span class="hljs-literal">null</span>,
    <span class="hljs-string">"summary"</span>: {
        <span class="hljs-string">"created"</span>: <span class="hljs-number">0</span>,
        <span class="hljs-string">"killed"</span>: <span class="hljs-number">0</span>,
        <span class="hljs-string">"pulled"</span>: <span class="hljs-number">0</span>,
        <span class="hljs-string">"removed"</span>: <span class="hljs-number">1</span>,
        <span class="hljs-string">"restarted"</span>: <span class="hljs-number">0</span>,
        <span class="hljs-string">"started"</span>: <span class="hljs-number">0</span>,
        <span class="hljs-string">"stopped"</span>: <span class="hljs-number">0</span>
    }
}
[root<span class="hljs-property">@host31</span> ~]<span class="hljs-comment">#</span>
[root<span class="hljs-property">@host31</span> ~]<span class="hljs-comment"># ansible host32 -m shell -a "docker ps -a"</span>
host32 | SUCCESS | rc=<span class="hljs-number">0</span> >>
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

[root<span class="hljs-property">@host31</span> ~]<span class="hljs-comment">#</span></code>

本文转载自 实例学习 ansible 系列(12)常用模块之 docker


蜷缩的蜗牛 , 版权所有丨如未注明 , 均为原创丨 转载请注明实例学习 ansible 系列(12)常用模块之 docker
喜欢 (0)
[]
分享 (0)