当前位置:   article > 正文

Docker5.Docker容器日志、进程、元数据信息_docker 元数据信息

docker 元数据信息

官放文档地址:https://docs.docker.com/engine/reference/commandline/inspect/

docker logs:查看容器日志

#语法:
docker logs [OPTIONS] CONTAINER
  • 1
  • 2
OPTIONS可选项默认值作用
–details显示提供给日志的额外详细信息
–follow , -f跟随日志输出
–since显示自时间戳(例如,2013-01-02T13:23:37Z)或相对(42m,42分钟)以来的日志
–tail , -nall从日志末尾显示的行数,默认all,即不加–tail就显示全部
–timestamps , -t显示时间戳
–until在时间戳前显示日志(例如,2013-01-02T13:23:37Z)或相对(例如,42m,42分钟)
sudo docker logs -tf --tail 10  容器id
  • 1
[haokai@localhost ~]$ sudo docker logs -t -f --tail 10  1015b6adbb9d
2021-11-04T06:06:43.758878819Z 04-Nov-2021 06:06:43.758 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded Apache Tomcat Native library [1.2.25] using APR version [1.6.5].
2021-11-04T06:06:43.758909433Z 04-Nov-2021 06:06:43.758 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
2021-11-04T06:06:43.758913351Z 04-Nov-2021 06:06:43.758 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
2021-11-04T06:06:43.769228534Z 04-Nov-2021 06:06:43.766 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.1.1d  10 Sep 2019]
2021-11-04T06:06:44.826362631Z 04-Nov-2021 06:06:44.823 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
2021-11-04T06:06:44.911943600Z 04-Nov-2021 06:06:44.910 INFO [main] org.apache.catalina.startup.Catalina.load Server initialization in [1888] milliseconds
2021-11-04T06:06:45.075817802Z 04-Nov-2021 06:06:45.075 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
2021-11-04T06:06:45.075843695Z 04-Nov-2021 06:06:45.075 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/9.0.41]
2021-11-04T06:06:45.107174534Z 04-Nov-2021 06:06:45.105 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
2021-11-04T06:06:45.128288838Z 04-Nov-2021 06:06:45.127 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in [216] milliseconds
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

docker top:查看容器中进程信息

docker top 容器id
  • 1
[haokai@localhost ~]$ sudo docker top 1015b6adbb9d
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
root                17365               17346               0                   14:06               ?                   00:00:09            /usr/local/openjdk-11/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start
[haokai@localhost ~]$
  • 1
  • 2
  • 3
  • 4

docker inspect :查看容器详细信息,元数据

#语法:
docker inspect [OPTIONS] NAME|ID [NAME|ID...]
  • 1
  • 2

测试的时候,可以运行容器时候跟一个命令来保证服务在运行


#-c后面的参数是shell脚本,对应docker inspect的args的值
sudo docker run -d --name="centos002" centos /bin/sh -c "while true;do echo 执行中;sleep 3;done"
  • 1
  • 2
  • 3

在这里插入图片描述

[haokai@localhost ~]$ sudo docker inspect 08d75c7a8f9b
[
    {
        "Id": "08d75c7a8f9b355cfa400b8a9c22c66662d8f10a4a105f4db30886616e3787b8",
        "Created": "2021-11-04T07:25:30.731548835Z",
        "Path": "/bin/sh",
        "Args": [
            "-c",
            "while true;do echo 执行中;sleep 3;done"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 19905,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2021-11-04T07:25:31.598803289Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:5d0da3dc976460b72c77d94c8a1ad043720b0416bfc16c52c45d4847e53fadb6",
        "ResolvConfPath": "/var/lib/docker/containers/08d75c7a8f9b355cfa400b8a9c22c66662d8f10a4a105f4db30886616e3787b8/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/08d75c7a8f9b355cfa400b8a9c22c66662d8f10a4a105f4db30886616e3787b8/hostname",
        "HostsPath": "/var/lib/docker/containers/08d75c7a8f9b355cfa400b8a9c22c66662d8f10a4a105f4db30886616e3787b8/hosts",
        "LogPath": "/var/lib/docker/containers/08d75c7a8f9b355cfa400b8a9c22c66662d8f10a4a105f4db30886616e3787b8/08d75c7a8f9b355cfa400b8a9c22c66662d8f10a4a105f4db30886616e3787b8-json.log",
        "Name": "/centos002",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {},
            "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/0fd4301904cf29a260ede8662d357e539bddd22ba3070f784bdec673442ff7c8-init/diff:/var/lib/docker/overlay2/33a0edd42edbc1dcba3b59935d25018e3e3419a957c6d8d2f9d010febe46a60a/diff",
                "MergedDir": "/var/lib/docker/overlay2/0fd4301904cf29a260ede8662d357e539bddd22ba3070f784bdec673442ff7c8/merged",
                "UpperDir": "/var/lib/docker/overlay2/0fd4301904cf29a260ede8662d357e539bddd22ba3070f784bdec673442ff7c8/diff",
                "WorkDir": "/var/lib/docker/overlay2/0fd4301904cf29a260ede8662d357e539bddd22ba3070f784bdec673442ff7c8/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [],
        "Config": {
            "Hostname": "08d75c7a8f9b",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "/bin/sh",
                "-c",
                "while true;do echo 执行中;sleep 3;done"
            ],
            "Image": "centos",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {
                "org.label-schema.build-date": "20210915",
                "org.label-schema.license": "GPLv2",
                "org.label-schema.name": "CentOS Base Image",
                "org.label-schema.schema-version": "1.0",
                "org.label-schema.vendor": "CentOS"
            }
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "fe1d05d363fad54938f7b25c5db1792447306d58d60a845cca8f451d7469036a",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "/var/run/docker/netns/fe1d05d363fa",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "f09dc1496d38cf8135af2eb04e91a277d886e800376f1f2b6ed0c69dfe94f16f",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.5",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:05",
            "Networks": {
                "bridge": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "7670d826dae37452ead1dc951ea1ddedaf13123e64ee6c0ff95042ec9f34096d",
                    "EndpointID": "f09dc1496d38cf8135af2eb04e91a277d886e800376f1f2b6ed0c69dfe94f16f",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.5",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:05",
                    "DriverOpts": null
                }
            }
        }
    }
]
[haokai@localhost ~]$

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210

常用操作

#获取实例的IP地址
docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $INSTANCE_ID

#获取实例的日志路径
docker inspect --format='{{.LogPath}}' $INSTANCE_ID

#获取实例的图像名称
docker inspect --format='{{.Config.Image}}' $INSTANCE_ID

#列出所有端口绑定
docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' $INSTANCE_ID
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小舞很执着/article/detail/1016189
推荐阅读
相关标签
  

闽ICP备14008679号