本 Docker 内容学习自:https://www.bilibili.com/video/BV1og4y1q7M4?p=13
为UP狂神的教程,也希望大家多去支持一下,因视频形式不方便回顾,便截图为图文形式,如有侵权立即设为私密。
Docker 常用命令
1 帮助命令
2 镜像命令
docker images 查看本地主机上的镜像
docker search 搜索镜像
docker pull 下载镜像
(上面的 Already exists 说明了 Docker 在安装环境方面的一处设计,如果当前版本的软件已经在之前下载的另一个版本中存在,那么便不再重复下载,极大节省了内存)
docker rmi 删除镜像
3 容器命令
需要有了系统镜像才可以创建容器,此处,我们先下载一个 CentOS 镜像
新建容器并启动容器
列出所有的运行的容器
退出容器
删除容器
启动和停止容器
4 其他常用命令
后台启动器
查看日志
查看容器中进程信息
查看镜像的元数据
docker inspect 容器id
[root@zlc ~]# docker inspect 4585f09daf61
[
{
"Id": "4585f09daf6173d2cd1da9af31fe15cf791ca5d96066f3aaeb48c8011318f8f8",
"Created": "2021-09-05T15:12:38.037136003Z",
"Path": "/bin/bash",
"Args": [],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 20928,
"ExitCode": 0,
"Error": "",
"StartedAt": "2021-09-05T15:14:07.038975342Z",
"FinishedAt": "2021-09-05T15:12:46.133388369Z"
},
"Image": "sha256:a0477e85b8aebf57d58bfa74a6598eccfd3fcc43a78c8e29c380cde2e7300a1b",
"ResolvConfPath": "/var/lib/docker/containers/4585f09daf6173d2cd1da9af31fe15cf791ca5d96066f3aaeb48c8011318f8f8/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/4585f09daf6173d2cd1da9af31fe15cf791ca5d96066f3aaeb48c8011318f8f8/hostname",
"HostsPath": "/var/lib/docker/containers/4585f09daf6173d2cd1da9af31fe15cf791ca5d96066f3aaeb48c8011318f8f8/hosts",
"LogPath": "/var/lib/docker/containers/4585f09daf6173d2cd1da9af31fe15cf791ca5d96066f3aaeb48c8011318f8f8/4585f09daf6173d2cd1da9af31fe15cf791ca5d96066f3aaeb48c8011318f8f8-json.log",
"Name": "/nervous_yalow",
"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/798e5432e868ebb080787a89055ecc340cfd7469be67da23feed45ff1a652c08-init/diff:/var/lib/docker/overlay2/6efc126718a70b186b330af4dc0fc26adccf16a063bcde39cc1e16ef52a114e4/diff",
"MergedDir": "/var/lib/docker/overlay2/798e5432e868ebb080787a89055ecc340cfd7469be67da23feed45ff1a652c08/merged",
"UpperDir": "/var/lib/docker/overlay2/798e5432e868ebb080787a89055ecc340cfd7469be67da23feed45ff1a652c08/diff",
"WorkDir": "/var/lib/docker/overlay2/798e5432e868ebb080787a89055ecc340cfd7469be67da23feed45ff1a652c08/work"
},
"Name": "overlay2"
},
"Mounts": [],
"Config": {
"Hostname": "4585f09daf61",
"Domainname": "",
"User": "",
"AttachStdin": true,
"AttachStdout": true,
"AttachStderr": true,
"Tty": true,
"OpenStdin": true,
"StdinOnce": true,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
],
"Cmd": [
"/bin/bash"
],
"Image": "centos",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"org.label-schema.build-date": "20201204",
"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": "579b2b1d2d87f1eb0135252f6349bc931df98ffffea0f6565337578dd030f5ae",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {},
"SandboxKey": "/var/run/docker/netns/579b2b1d2d87",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "beecd9d42796c1ba972efc99658b3f8fe0ef15732bcc87c30425f499812d3285",
"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": "859c97d47023ebdd0cd2b4d895a3f8d037a93872c9ade9ca284674d9564913ae",
"EndpointID": "beecd9d42796c1ba972efc99658b3f8fe0ef15732bcc87c30425f499812d3285",
"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
}
}
}
}
]
进入当前正在运行的容器
从容器内拷贝文件到主机
5 小结