332
docker运维
乐果 发表于 2024 年 05 月 16 日 标签:Docker
最近参与一些运维工作,因此做一下容器运维的常用命令笔记。
docker ps
docker ps命令参数:
-a
显示所有容器,包括停止状态的--format
输出格式(ID,Names,Image,Created,Status,Ports,Command)--no-trunc
显示完整的输出格式(包括Command)
如下所示:
docker ps --no-trunc --format "table {{.Names}}\t{{.Image}}\t{{.Command}}"
docker ps --no-trunc --format "table {{.ID}}\t{{.Names}}\t{{.Image}}\t{{.Command}}"
docker ps --no-trunc --format "table {{.ID}}\t{{.Names}}\t{{.Image}}\t{{.Ports}}\t{{.Command}}"
docker inspect
docker inspect 用于查看某容器的运行状态,例如:
docker inspect Pro-MySQL8035
[
{
"Id": "fdc8330fb485051528cb8f00440e74d639e3b85201336b0b9ecb814a9fd1997d",
"Created": "2024-04-03T03:25:38.109757289Z",
"Path": "docker-entrypoint.sh",
"Args": [
"mysqld"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 36350,
"ExitCode": 0,
"Error": "",
"StartedAt": "2024-04-03T03:25:38.299106795Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:6edae131fea9931df7b6d3d95ba63bc556e74d778bb17e2db173a460774f7deb",
"ResolvConfPath": "/data/docker/containers/fdc8330fb485051528cb8f00440e74d639e3b85201336b0b9ecb814a9fd1997d/resolv.conf",
"HostnamePath": "/data/docker/containers/fdc8330fb485051528cb8f00440e74d639e3b85201336b0b9ecb814a9fd1997d/hostname",
"HostsPath": "/data/docker/containers/fdc8330fb485051528cb8f00440e74d639e3b85201336b0b9ecb814a9fd1997d/hosts",
"LogPath": "/data/docker/containers/fdc8330fb485051528cb8f00440e74d639e3b85201336b0b9ecb814a9fd1997d/fdc8330fb485051528cb8f00440e74d639e3b85201336b0b9ecb814a9fd1997d-json.log",
"Name": "/Pro-MySQL8035",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "docker-default",
"ExecIDs": null,
"HostConfig": {
"Binds": [
"/data/mysql/conf.d:/etc/mysql/conf.d:rw",
"/data/mysql/data:/var/lib/mysql:rw",
"/data/mysql/logs:/var/log/mysql:rw"
],
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {
"max-file": "5",
"max-size": "30m"
}
},
"NetworkMode": "ProNet",
"PortBindings": {
"3306/tcp": [
{
"HostIp": "",
"HostPort": "3306"
}
]
},
"RestartPolicy": {
"Name": "always",
"MaximumRetryCount": 0
},
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"ConsoleSize": [
0,
0
],
"CapAdd": null,
"CapDrop": null,
"CgroupnsMode": "private",
"Dns": null,
"DnsOptions": null,
"DnsSearch": null,
"ExtraHosts": [],
"GroupAdd": null,
"IpcMode": "private",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": [
"seccomp:unconfined"
],
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"Isolation": "",
"CpuShares": 0,
"Memory": 0,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": null,
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": null,
"DeviceCgroupRules": null,
"DeviceRequests": null,
"MemoryReservation": 0,
"MemorySwap": 0,
"MemorySwappiness": null,
"OomKillDisable": null,
"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",
"/sys/devices/virtual/powercap"
],
"ReadonlyPaths": [
"/proc/bus",
"/proc/fs",
"/proc/irq",
"/proc/sys",
"/proc/sysrq-trigger"
]
},
"GraphDriver": {
"Data": {
"LowerDir": "/data/docker/overlay2/972af6b08320769d36503216894e96d1808db3d4dd206053baf8b7c57a452cd0-init/diff:/data/docker/overlay2/3089f113b23efffea133ae2c98b603cc7ba9b1487f90503890d4d1342d792cff/diff:/data/docker/overlay2/37f696b52013f521e09b0a855bef4f14a730d0b6c7b4618c8396078989481b9c/diff:/data/docker/overlay2/53feb4337056a81f0dccbfcb4aa045cf8fbb68fed6f67a0a245a514873b5f907/diff:/data/docker/overlay2/da2644551c2bc71cb125adf6deafb6c388ebc7e87c34dc2258c900963f8c8564/diff:/data/docker/overlay2/9a43ccb98e2c6cdbdea66bd444bc793192a212ab0d5a4a230598ea0711dca7ba/diff:/data/docker/overlay2/275e610d0d31555a2fd612e488e368a9e43b7681d1969b736947690a0c1185dd/diff:/data/docker/overlay2/da54242d1aaadc4b0ee2b07a6f824d9fcf5e16015cfbfa4100dc27ed3a733e1b/diff:/data/docker/overlay2/6a76e4e06b1c497143db49e94a35985d789518c5129ca397e578b656af003cc8/diff:/data/docker/overlay2/a7d5e338ee28b50eb2dd290e3009f85910c1a22269db42151504bc3dab69da84/diff:/data/docker/overlay2/928f4ffcc91656cc4d3d4d512dd6f01d7556dc42672580167e435955f0d0c974/diff:/data/docker/overlay2/3c678e5cb13d545f5de2eeebdb311a01042c5c92249b6bba4869ec95aa7f707c/diff:/data/docker/overlay2/41240480a75b080a31913b0cfe039181d77061c55d1ebe6511c4d7d0f0f87ab5/diff",
"MergedDir": "/data/docker/overlay2/972af6b08320769d36503216894e96d1808db3d4dd206053baf8b7c57a452cd0/merged",
"UpperDir": "/data/docker/overlay2/972af6b08320769d36503216894e96d1808db3d4dd206053baf8b7c57a452cd0/diff",
"WorkDir": "/data/docker/overlay2/972af6b08320769d36503216894e96d1808db3d4dd206053baf8b7c57a452cd0/work"
},
"Name": "overlay2"
},
"Mounts": [
{
"Type": "bind",
"Source": "/data/mysql/logs",
"Destination": "/var/log/mysql",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"
},
{
"Type": "bind",
"Source": "/data/mysql/conf.d",
"Destination": "/etc/mysql/conf.d",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"
},
{
"Type": "bind",
"Source": "/data/mysql/data",
"Destination": "/var/lib/mysql",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"
}
],
"Config": {
"Hostname": "fdc8330fb485",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": true,
"AttachStderr": true,
"ExposedPorts": {
"3306/tcp": {},
"33060/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"MYSQL_ROOT_PASSWORD=test#papa2014",
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"GOSU_VERSION=1.16",
"MYSQL_MAJOR=8.0",
"MYSQL_VERSION=8.0.35-1debian11"
],
"Cmd": [
"mysqld"
],
"Image": "mysql:8.0.35-debian",
"Volumes": {
"/var/lib/mysql": {}
},
"WorkingDir": "",
"Entrypoint": [
"docker-entrypoint.sh"
],
"OnBuild": null,
"Labels": {
"com.docker.compose.config-hash": "08dd32b1220ae758373376ead471da1252317c279c442ba94635d4fc1e65c9cf",
"com.docker.compose.container-number": "1",
"com.docker.compose.depends_on": "",
"com.docker.compose.image": "sha256:6edae131fea9931df7b6d3d95ba63bc556e74d778bb17e2db173a460774f7deb",
"com.docker.compose.oneoff": "False",
"com.docker.compose.project": "mysql",
"com.docker.compose.project.config_files": "/data/mysql/dbs-mysql8035.compose.yml",
"com.docker.compose.project.working_dir": "/data/mysql",
"com.docker.compose.service": "mysql8035",
"com.docker.compose.version": "2.24.5"
}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "c92cc9499d3e4babb0d5f290f5428c966c2c3ceb54cc47c7023941a9ef8b83a0",
"SandboxKey": "/var/run/docker/netns/c92cc9499d3e",
"Ports": {
"3306/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "3306"
},
{
"HostIp": "::",
"HostPort": "3306"
}
],
"33060/tcp": null
},
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks": {
"ProNet": {
"IPAMConfig": {
"IPv4Address": "172.23.23.233"
},
"Links": null,
"Aliases": [
"Pro-MySQL8035",
"mysql8035",
"fdc8330fb485"
],
"MacAddress": "02:42:ac:17:17:e9",
"NetworkID": "2ad1c88da7887f6fc8e9229406c72f75d1b43cc68d916a47131010d99450a73b",
"EndpointID": "f4621a616e809c7dd945bbbaf947e47f1deed0cf32916af66d463a001ac154e7",
"Gateway": "172.23.23.1",
"IPAddress": "172.23.23.233",
"IPPrefixLen": 24,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"DriverOpts": null,
"DNSNames": [
"Pro-MySQL8035",
"mysql8035",
"fdc8330fb485"
]
}
}
}
}
]
后续不断补充…
乐果 发表于 2024 年 05 月 16 日 标签:Docker