docker container在停止或删除后启动新容器

时间:2017-07-30 15:22:13

标签: python docker

我在官方docker网站上关注了“开始”tutorial,一切顺利,直到我尝试删除容器。每次我跑

docker rm -f [container_id]

docker stop -f [container_id]

具有该ID的初始容器将被停止或删除,但新容器将出现并运行。我尝试使用以下命令更新容器:

docker update --restart=no $(docker ps -aq)

然而它没有帮助。

这里'docker info'命令结果:

$ docker info
Containers: 5
 Running: 5
 Paused: 0
 Stopped: 0
Images: 1
Server Version: 17.05.0-ce
Storage Driver: aufs
 Root Dir: /var/lib/docker/aufs
 Backing Filesystem: extfs
 Dirs: 22
 Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins: 
 Volume: local
 Network: bridge host macvlan null overlay
Swarm: active
 NodeID: qpmjeqewpl5hnneuhm99dp7g7
 Is Manager: true
 ClusterID: x14jwe053zapko55g7edlh9fp
 Managers: 1
 Nodes: 1
 Orchestration:
  Task History Retention Limit: 5
 Raft:
  Snapshot Interval: 10000
  Number of Old Snapshots to Retain: 0
  Heartbeat Tick: 1
  Election Tick: 3
 Dispatcher:
  Heartbeat Period: 5 seconds
 CA Configuration:
  Expiry Duration: 3 months
 Node Address: 192.168.0.108
 Manager Addresses:
  192.168.0.108:2377
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 9048e5e50717ea4497b757314bad98ea3763c145
runc version: 9c2d8d184e5da67c95d601382adf14862e4f2228
init version: 949e6fa
Security Options:
 apparmor
 seccomp
  Profile: default
Kernel Version: 4.10.0-28-generic
Operating System: Ubuntu 16.04.2 LTS
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 5.74GiB
Name: roman-LIFEBOOK-AH531
ID: BHNU:2PGO:UDAA:MFYE:XGLO:R4PS:27QR:GXF6:KZME:W4EN:C5VO:FIJM
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Username: rmcontkit
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

和'docker inspect [container_id]'

$ docker inspect f53643ac5f9b
[
    {
        "Id": "f53643ac5f9b105c6b0d09de43eecd01f9d8bc3a20c71a535c1a25818db64775",
        "Created": "2017-07-30T15:03:23.009739796Z",
        "Path": "python",
        "Args": [
            "app.py"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 10661,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2017-07-30T15:03:30.614115776Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:413941614a833af57c05119d70cae063e0dc164b919e8ec84c6af595e7225b85",
        "ResolvConfPath": "/var/lib/docker/containers/f53643ac5f9b105c6b0d09de43eecd01f9d8bc3a20c71a535c1a25818db64775/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/f53643ac5f9b105c6b0d09de43eecd01f9d8bc3a20c71a535c1a25818db64775/hostname",
        "HostsPath": "/var/lib/docker/containers/f53643ac5f9b105c6b0d09de43eecd01f9d8bc3a20c71a535c1a25818db64775/hosts",
        "LogPath": "/var/lib/docker/containers/f53643ac5f9b105c6b0d09de43eecd01f9d8bc3a20c71a535c1a25818db64775/f53643ac5f9b105c6b0d09de43eecd01f9d8bc3a20c71a535c1a25818db64775-json.log",
        "Name": "/getstartedlab_web.2.yr7k0egu4ketu7m0kdxt7v3o7",
        "RestartCount": 0,
        "Driver": "aufs",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "docker-default",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {},
            "RestartPolicy": {
                "Name": "",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "Dns": null,
            "DnsOptions": null,
            "DnsSearch": null,
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 52428800,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 100000,
            "CpuQuota": 10000,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": null,
            "DeviceCgroupRules": null,
            "DiskQuota": 0,
            "KernelMemory": 0,
            "MemoryReservation": 0,
            "MemorySwap": -1,
            "MemorySwappiness": -1,
            "OomKillDisable": false,
            "PidsLimit": 0,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0
        },
        "GraphDriver": {
            "Data": null,
            "Name": "aufs"
        },
        "Mounts": [],
        "Config": {
            "Hostname": "f53643ac5f9b",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "80/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "LANG=C.UTF-8",
                "GPG_KEY=C01E1CAD5EA2C4F0B8E3571504C367C218ADD4FF",
                "PYTHON_VERSION=2.7.13",
                "PYTHON_PIP_VERSION=9.0.1",
                "NAME=World"
            ],
            "Cmd": [
                "python",
                "app.py"
            ],
            "ArgsEscaped": true,
            "Image": "rmcontkit/get-started:part1@sha256:e7c1e776eb3eca11213449a8621cc84f989cb127350c3207ae8c610d482c0398",
            "Volumes": null,
            "WorkingDir": "/app",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {
                "com.docker.stack.namespace": "getstartedlab",
                "com.docker.swarm.node.id": "qpmjeqewpl5hnneuhm99dp7g7",
                "com.docker.swarm.service.id": "8dj5jmxiqcip81ay1we2yd8uc",
                "com.docker.swarm.service.name": "getstartedlab_web",
                "com.docker.swarm.task": "",
                "com.docker.swarm.task.id": "yr7k0egu4ketu7m0kdxt7v3o7",
                "com.docker.swarm.task.name": "getstartedlab_web.2.yr7k0egu4ketu7m0kdxt7v3o7"
            }
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "e6d8f06b6ca25b73c100921213fe47dd4fc93eaf95db09be2dc0191b989aa139",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "80/tcp": null
            },
            "SandboxKey": "/var/run/docker/netns/e6d8f06b6ca2",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "getstartedlab_webnet": {
                    "IPAMConfig": {
                        "IPv4Address": "10.0.0.7"
                    },
                    "Links": null,
                    "Aliases": [
                        "f53643ac5f9b"
                    ],
                    "NetworkID": "k3as780fjdoywrdxdiabned7u",
                    "EndpointID": "44933d5909d3ff46c34e9a28317d5eaf025497ab61b951dbf054853415634c6e",
                    "Gateway": "",
                    "IPAddress": "10.0.0.7",
                    "IPPrefixLen": 24,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:0a:00:00:07"
                },
                "ingress": {
                    "IPAMConfig": {
                        "IPv4Address": "10.255.0.8"
                    },
                    "Links": null,
                    "Aliases": [
                        "f53643ac5f9b"
                    ],
                    "NetworkID": "6um0tpqyj5pkl12xzklmt7vdv",
                    "EndpointID": "20a9ac122ba2cdcda5827b2d54688426d1df0dafa20afa70bf8f65b387d07b77",
                    "Gateway": "",
                    "IPAddress": "10.255.0.8",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:0a:ff:00:08"
                }
            }
        }
    }
]

1 个答案:

答案 0 :(得分:2)

这可能是因为你正在运行一个docker swarm堆栈,它负载平衡运行的节点数。尝试使用以下内容删除堆栈:

docker stack rm getstartedlab

正如他们在网站上建议的那样。