娜尼的妮妮

导航

Docker container 的相关命令

1 删除host机器上所有的container

docker rm -f $(docker ps -a -q)

  

2 run container 从dockerhub上

docker run -d -p 5000:5000 --name app1 selaworkshops/python-app:1.0
docker run -d -p 5001:5001 -e "port=5001" --name app2 selaworkshops/python-app:2.0

  

3 stop container app1

docker stop app1

  

4 kill 第二个container

docker kill app2

  

5 列出所有的container,包括non running 的

docker ps -a

  

6 docker start & docker restart

docker start app1 app2
docker restart app2

  

7 查看docker host info

docker info

 

8 查看container内运行的线程

docker top app1

  

9 查看container的历史信息

docker history selaworkshops/python-app:2.0

  

10 查看docker container的具体信息

docker inspect app1
[
    {
        "Id": "8a817e0467f2a70ed5747a0c6937e6d2a31df77c79066e4304fe30ed052deda4",
        "Created": "2021-07-29T06:20:05.495945601Z",
        "Path": "/bin/sh",
        "Args": [
            "-c",
            "python -m SimpleHTTPServer 5000"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 15462,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2021-07-29T06:22:38.062575762Z",
            "FinishedAt": "2021-07-29T06:21:47.174049956Z"
        },
        "Image": "sha256:e89ed9ac54f866310182335d08cfd0f706454be1cff1dede146fb7c05746b2ae",
        "ResolvConfPath": "/var/lib/docker/containers/8a817e0467f2a70ed5747a0c6937e6d2a31df77c79066e4304fe30ed052deda4/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/8a817e0467f2a70ed5747a0c6937e6d2a31df77c79066e4304fe30ed052deda4/hostname",
        "HostsPath": "/var/lib/docker/containers/8a817e0467f2a70ed5747a0c6937e6d2a31df77c79066e4304fe30ed052deda4/hosts",
        "LogPath": "/var/lib/docker/containers/8a817e0467f2a70ed5747a0c6937e6d2a31df77c79066e4304fe30ed052deda4/8a817e0467f2a70ed5747a0c6937e6d2a31df77c79066e4304fe30ed052deda4-json.log",
        "Name": "/app1",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "docker-default",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {
                "5000/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "5000"
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "CgroupnsMode": "host",
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "private",
            "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": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": [],
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "KernelMemory": 0,
            "KernelMemoryTCP": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": null,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "MaskedPaths": [
                "/proc/asound",
                "/proc/acpi",
                "/proc/kcore",
                "/proc/keys",
                "/proc/latency_stats",
                "/proc/timer_list",
                "/proc/timer_stats",
                "/proc/sched_debug",
                "/proc/scsi",
                "/sys/firmware"
            ],
            "ReadonlyPaths": [
                "/proc/bus",
                "/proc/fs",
                "/proc/irq",
                "/proc/sys",
                "/proc/sysrq-trigger"
            ]
        },
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/f38a71bdd62e49a2bc37a7d6dd1488461f934be98a7dd880a5fad3bf136e1878-init/diff:/var/lib/docker/overlay2/b1543bacea6860e69e798aefe296ec1d7f322014e9bfb5064b15c14ef4a162d9/diff:/var/lib/docker/overlay2/87c7c31651f09f3121ba13aa164c19afa44fe9f520d391ad64365831d244c265/diff",
                "MergedDir": "/var/lib/docker/overlay2/f38a71bdd62e49a2bc37a7d6dd1488461f934be98a7dd880a5fad3bf136e1878/merged",
                "UpperDir": "/var/lib/docker/overlay2/f38a71bdd62e49a2bc37a7d6dd1488461f934be98a7dd880a5fad3bf136e1878/diff",
                "WorkDir": "/var/lib/docker/overlay2/f38a71bdd62e49a2bc37a7d6dd1488461f934be98a7dd880a5fad3bf136e1878/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [],
        "Config": {
            "Hostname": "8a817e0467f2",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "5000/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "/bin/sh",
                "-c",
                "python -m SimpleHTTPServer 5000"
            ],
            "Image": "selaworkshops/python-app:1.0",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {}
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "b0454d80fcf5d14ec4fe1150cdb17f75aaf0f83ee975215c6dd841a881f5fb3a",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "5000/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "5000"
                    }
                ]
            },
            "SandboxKey": "/var/run/docker/netns/b0454d80fcf5",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "51394afbce79d2f83ccbd8184ea964b1642e0ae58722663760511786cf337bb9",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.2",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:02",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "9080688a5ccfffbcdd9866624faec0a307619d6d394031fc1892d06af59df4a0",
                    "EndpointID": "51394afbce79d2f83ccbd8184ea964b1642e0ae58722663760511786cf337bb9",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:02",
                    "DriverOpts": null
                }
            }
        }
    }
]

  

posted on 2021-07-29 14:36  娜尼的妮妮  阅读(88)  评论(0编辑  收藏  举报