赞
踩
官放文档地址:https://docs.docker.com/engine/reference/commandline/inspect/
#语法:
docker logs [OPTIONS] CONTAINER
OPTIONS可选项 | 默认值 | 作用 |
---|---|---|
–details | 显示提供给日志的额外详细信息 | |
–follow , -f | 跟随日志输出 | |
–since | 显示自时间戳(例如,2013-01-02T13:23:37Z)或相对(42m,42分钟)以来的日志 | |
–tail , -n | all | 从日志末尾显示的行数,默认all,即不加–tail就显示全部 |
–timestamps , -t | 显示时间戳 | |
–until | 在时间戳前显示日志(例如,2013-01-02T13:23:37Z)或相对(例如,42m,42分钟) |
sudo docker logs -tf --tail 10 容器id
[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
docker top 容器id
[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 ~]$
#语法:
docker inspect [OPTIONS] NAME|ID [NAME|ID...]
测试的时候,可以运行容器时候跟一个命令来保证服务在运行
#-c后面的参数是shell脚本,对应docker inspect的args的值
sudo docker run -d --name="centos002" centos /bin/sh -c "while true;do echo 执行中;sleep 3;done"
[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 ~]$
#获取实例的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
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。