赞
踩
后台启动容器
#常见坑
#docker容器使用后台运行,就必须要有一个前台进程,docker发现没有应用,就会自动停止
#nginx,容器启动后,发现自己没有提供服务,就会立刻停止,就是没有程序了
docker run -d centos #后台启动容器
查看日志
[root@xiaoxiao ~]# docker logs --help
Usage: docker logs [OPTIONS] CONTAINER
Fetch the logs of a container
Options:
--details Show extra details provided to logs
-f, --follow Follow log output
--since string Show logs since timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes)
--tail string Number of lines to show from the end of the logs (default "all")
-t, --timestamps Show timestamps
--until string Show logs before a timestamp (e.g. 2013-01-02T13:23:37) or relative (e.g. 42m for 42 minutes)
#显示日志 -tf #显示日志 --tail number #要显示日志的条数 #查看日志 docker logs -tf --tail 10 容器id #没有日志 #自己编写一段脚本 while true; do echo xiaomin; sleep 2 #看一下在docker中实现 [root@xiaoxiao ~]# docker run -d centos /bin/bash -c "while true; do echo xiaomin; sleep 1;done" 289fc5495bfefab4adf11147cdb31aacea264c7ee4eb5db1f44f090a31562ec7 [root@xiaoxiao ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 289fc5495bfe centos "/bin/bash -c 'while…" 4 seconds ago Up 3 seconds sharp_bohr [root@xiaoxiao ~]# docker logs -tf --tail 10 289fc5495bfe 2020-08-26T00:30:17.070270383Z xiaomin 2020-08-26T00:30:18.072306356Z xiaomin 2020-08-26T00:30:19.074364572Z xiaomin 2020-08-26T00:30:20.076290509Z xiaomin 2020-08-26T00:30:21.078480156Z xiaomin
查看容器中的进程信息
#命令 docker top 容器id
[root@xiaoxiao ~]# docker top 289fc5495bfe
UID PID PPID C STIME TTY TIME CMD
root 19558 19542 0 08:29 ? 00:00:00 /bin/bash -c while true; do echo xiaomin; sleep 1;done
root 20030 19558 0 08:36 ? 00:00:00 /usr/bin/coreutils --coreutils-prog-shebang=sleep /usr/bin/sleep 1
查看镜像的元数据
#命令 docker inspect 容器id #测试 [root@xiaoxiao ~]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 289fc5495bfe centos "/bin/bash -c 'while…" 9 minutes ago Up 9 minutes sharp_bohr a85dc0ea2163 centos "/bin/bash -C 'while…" 9 minutes ago Exited (127) 9 minutes ago hungry_mcnulty 4d3d269fa715 centos "/bin/bash -C 'while…" 11 minutes ago Exited (127) 11 minutes ago nice_kilby 95608bcb75bb centos "/bin/bash" 18 minutes ago Exited (0) 10 minutes ago objective_poitras 72bc1e52bf20 centos "/bin/bash" 18 minutes ago Exited (0) 9 minutes ago eager_golick c1201b7a894d centos "/bin/bash" 24 hours ago Exited (127) 24 hours ago suspicious_tu [root@xiaoxiao ~]# docker inspect 289fc5495bfe [ { "Id": "289fc5495bfefab4adf11147cdb31aacea264c7ee4eb5db1f44f090a31562ec7", "Created": "2020-08-26T00:29:34.7069754Z", "Path": "/bin/bash", "Args": [ "-c", "while true; do echo xiaomin; sleep 1;done" ], "State": { "Status": "running", "Running": true, "Paused": false, "Restarting": false, "OOMKilled": false, "Dead": false, "Pid": 19558, "ExitCode": 0, "Error": "", "StartedAt": "2020-08-26T00:29:34.96551302Z", "FinishedAt": "0001-01-01T00:00:00Z" }, "Image": "sha256:0d120b6ccaa8c5e149176798b3501d4dd1885f961922497cd0abef155c869566", "ResolvConfPath": "/var/lib/docker/containers/289fc5495bfefab4adf11147cdb31aacea264c7ee4eb5db1f44f090a31562ec7/resolv.conf", "HostnamePath": "/var/lib/docker/containers/289fc5495bfefab4adf11147cdb31aacea264c7ee4eb5db1f44f090a31562ec7/hostname", "HostsPath": "/var/lib/docker/containers/289fc5495bfefab4adf11147cdb31aacea264c7ee4eb5db1f44f090a31562ec7/hosts", "LogPath": "/var/lib/docker/containers/289fc5495bfefab4adf11147cdb31aacea264c7ee4eb5db1f44f090a31562ec7/289fc5495bfefab4adf11147cdb31aacea264c7ee4eb5db1f44f090a31562ec7-json.log", "Name": "/sharp_bohr", "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, "Capabilities": null, "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/143de83210d8fef509c3242ae126cf48ee2d31bd0ff222fa4e6b368f150599df-init/diff:/var/lib/docker/overlay2/ac620cd9172b1214e98ef8369c5b148a6d5404b1abdb92d338129c6ea24d4f16/diff", "MergedDir": "/var/lib/docker/overlay2/143de83210d8fef509c3242ae126cf48ee2d31bd0ff222fa4e6b368f150599df/merged", "UpperDir": "/var/lib/docker/overlay2/143de83210d8fef509c3242ae126cf48ee2d31bd0ff222fa4e6b368f150599df/diff", "WorkDir": "/var/lib/docker/overlay2/143de83210d8fef509c3242ae126cf48ee2d31bd0ff222fa4e6b368f150599df/work" }, "Name": "overlay2" }, "Mounts": [], "Config": { "Hostname": "289fc5495bfe", "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/bash", "-c", "while true; do echo xiaomin; sleep 1;done" ], "Image": "centos", "Volumes": null, "WorkingDir": "", "Entrypoint": null, "OnBuild": null, "Labels": { "org.label-schema.build-date": "20200809", "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": "2529e3af850bed2dadb9e4d30dcd8ed307418a162200c83fd73724bcebb2b6bc", "HairpinMode": false, "LinkLocalIPv6Address": "", "LinkLocalIPv6PrefixLen": 0, "Ports": {}, "SandboxKey": "/var/run/docker/netns/2529e3af850b", "SecondaryIPAddresses": null, "SecondaryIPv6Addresses": null, "EndpointID": "baf16bc2cb969097eab7dba68bc9b26153f321e10c86b822e3109a24bfdb49bb", "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": "28723bf3763d6fa1dfb17c9c351bb9016cf2fd0f6ab7b21dc4c03f588a5673b6", "EndpointID": "baf16bc2cb969097eab7dba68bc9b26153f321e10c86b822e3109a24bfdb49bb", "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 } } } } ]
好了,今天先到这里呢,还有更好玩的在后面呢~
这个是我看B站up主狂神的笔记,大家也可以去看,很有趣~
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。