Docker的基本命令
镜像命令
[root@VM-8-14-centos docker]
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest d1165f221234 5 months ago 13.3kB
REPOSITORY 镜像的仓库源
TAG 镜像的标签
IMAGE ID 镜像的id
CREATED 镜像的创建时间
SIZE 镜像的大小
-a, --all
-q,--quiet
docker search 搜索镜像
[root@VM-8-14-centos docker]
NAME DESCRIPTION STARS
mysql MySQL is a widely used, open-source relation… 11294
mariadb MariaDB Server is a high performing open sou… 4289
mysql/mysql-server Optimized MySQL Server Docker images. Create… 837
--filter=STARS=3000 搜索出来的镜像就是STARS数量大于3000的
docker pull 下载镜像
[root@VM-8-14-centos docker]
Using default tag: latest
latest: Pulling from library/mysql
e1acddbe380c: Pulling fs layer
bed879327370: Pulling fs layer
03285f80bafd: Pulling fs layer
ccc17412a00a: Pull complete
1f556ecc09d1: Pull complete
adc5528e468d: Pull complete
1afc286d5d53: Pull complete
6c724a59adff: Pull complete
0f2345f8b0a3: Pull complete
c8461a25b23b: Pull complete
3adb49279bed: Pull complete
77f22cd6c363: Pull complete
Digest: sha256:d45561a65aba6edac77be36e0a53f0c1fba67b951cb728348522b671ad63f926
Status: Downloaded newer image for mysql:latest
docker.io/library/mysql:latest
[root@VM-8-14-centos docker]
5.7: Pulling from library/mysql
e1acddbe380c: Already exists
bed879327370: Already exists
03285f80bafd: Already exists
ccc17412a00a: Already exists
1f556ecc09d1: Already exists
adc5528e468d: Already exists
1afc286d5d53: Already exists
4d2d9261e3ad: Pull complete
ac609d7b31f8: Pull complete
53ee1339bc3a: Pull complete
b0c0a831a707: Pull complete
Digest: sha256:7cf2e7d7ff876f93c8601406a5aa17484e6623875e64e7acc71432ad8e0a3d7e
Status: Downloaded newer image for mysql:5.7
docker.io/library/mysql:5.7
docker 删除镜像
[root@VM-8-14-centos docker]
Untagged: mysql:5.7
Untagged: mysql@sha256:7cf2e7d7ff876f93c8601406a5aa17484e6623875e64e7acc71432ad8e0a3d7e
Deleted: sha256:6c20ffa54f8674203e91e3225e489aa505fa04b8d482954a8b6d7414842c6de4
Deleted: sha256:7ecf077dd9d6725f0e594b9cd5eb214ad1b3764fa75bf5940ab08b05b8bae184
Deleted: sha256:c28edab85681de37f9d2a75dde941a20d2e1ac6e4efb7dee391913d3ec722fef
Deleted: sha256:6c11b187da1ecb65ce10b25f54354f3515ce9d26fabcd859cdb43dbd625df907
Deleted: sha256:d0dfc5be0883ed4af9f642a8e4f2312a93c4241ec8e89f22219b0f0a0d26c8d3
[root@VM-8-14-centos docker]
Untagged: mysql:latest
Untagged: mysql@sha256:d45561a65aba6edac77be36e0a53f0c1fba67b951cb728348522b671ad63f926
Deleted: sha256:5a4e492065c722ec8cc7413552bafc6fd5434c5ad90797e898ccc4e347e21aa5
Deleted: sha256:816bf92c28337cd97393cb1fab7697398c9b657baa8e80ad394e1193bdd7c323
Deleted: sha256:4d9cad11f64589b397b1033d6f14cea1794efbee0a9923932fb3394a67cb9812
Deleted: sha256:d8cc28a31b469770ffe2239a29aaef8745fedc4df3c545b1615ba864796709a3
Deleted: sha256:c65a377e07f1205f3c28f7067d2ac4da3a65fbe7c1b4606b48028db3818d2f4c
Deleted: sha256:7dcd840f1d4be1a565f470453489932a17c62ed36b959d7839f004606ba22f0b
Deleted: sha256:1438a7497295aed687ea1875073a1f9faa6a308f787767b952da4a1a21e2c2c6
Deleted: sha256:c728863b4742db55b9630b0129abac718c8c9704e5ed86e8af93dfb47a0f6214
Deleted: sha256:0f12df3ff796b6fb619c63bf2f78f16d1033746e19f75ffc2d8d72ea69242ad4
Deleted: sha256:3072318e40ebff019298a59290e615ad6170a651f3121c0e356dcf3dd7426136
Deleted: sha256:a69e3133dd3c0a81bd439120abb8f98e43c1581629896725b968db906c8fdfac
Deleted: sha256:6d9498fd63c38c4b0b9bbc563087b4bc164b2fb5211832a8d43c60a9692a7f84
Deleted: sha256:f68ef921efae588b3dd5cc466a1ca9c94c24785f1fa9420bea15ecc2dedbe781
Untagged: hello-world:latest
Untagged: hello-world@sha256:0fe98d7debd9049c50b597ef1f85b7c1e8cc81f59c8d623fcb2250e8bec85b38
Deleted: sha256:d1165f2212346b2bab48cb01c1e39ee8ad1be46b87873d9ca7a4e434980a7726
[root@VM-8-14-centos docker]
REPOSITORY TAG IMAGE ID CREATED SIZE
容器命令
说明:我们有了镜像才可以创建容器,linux,下载一个centos镜像来测试学习
docker pull centos
新建容器并启动
docker run [可选参数] image
--name="Name" 容器名字 tomcat1 tomcat2 用于区分容器
-d 后台方式运行
-it 使用交互方式运行,进入容器查看内容
-p 指定容器的端口 -p 8080:8080
-p ip:主机端口:容器端口
-p 主机端口:容器端口(常用)
-p 容器端口
容器端口
[root@VM-8-14-centos docker]
[root@ac71b5898083 /]
[root@ac71b5898083 /]
bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin srv sys tmp usr var
[root@9af1a7b253ec /]
exit
[root@VM-8-14-centos /]
列出所有运行的容器
-a
-n=?
-q
[root@VM-8-14-centos /]
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
[root@VM-8-14-centos /]
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9af1a7b253ec centos "/bin/bash" About a minute ago Exited (0) About a minute ago happy_nash
ac71b5898083 centos "/bin/bash" 3 minutes ago Exited (0) 2 minutes ago sleepy_sutherland
e1c59d0e993b d1165f221234 "/hello" 24 hours ago Exited (0) 24 hours ago quizzical_albattani
[root@VM-8-14-centos /]
退出容器
exit
Ctrl+P+Q
删除容器
docker rm 容器id
docker rm -f $(docker ps -aq)
docker ps -a -q|xargs docker rm
启动和停止容器的操作
docker start 容器id
docker restart 容器id
docker stop 容器id
docker kill 容器id
常用其他命令
后台启动容器
[root@VM-8-14-centos /]
查看日志
[root@VM-8-14-centos /]
88e36a8819f26f5d12a8fd658adfbb97ed60901a71a8d878a0d8174b98b72dd7
[root@VM-8-14-centos /]
2021-08-18T14:17:58.098503211Z fanxu
2021-08-18T14:17:59.100849355Z fanxu
2021-08-18T14:18:00.103158743Z fanxu
2021-08-18T14:18:01.105462026Z fanxu
2021-08-18T14:18:02.107828632Z fanxu
查看容器中进程信息
[root@VM-8-14-centos /]
UID PID PPID C STIME TTY TIME CMD
root 20586 20568 0 22:20 pts/0 00:00:00 /bin/bash
查看镜像的源数据
docker inspect 容器id
[root@VM-8-14-centos /]
[
{
"Id": "81d323846d11ab383afd98a34aef5feff5fd2646865a0023e04be4967e712c02",
"Created": "2021-08-18T14:20:55.98150614Z",
"Path": "/bin/bash",
"Args": [],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 21525,
"ExitCode": 0,
"Error": "",
"StartedAt": "2021-08-18T14:24:47.97344561Z",
"FinishedAt": "2021-08-18T14:21:26.415512597Z"
},
"Image": "sha256:300e315adb2f96afe5f0b2780b87f28ae95231fe3bdd1e16b9ba606307728f55",
"ResolvConfPath": "/var/lib/docker/containers/81d323846d11ab383afd98a34aef5feff5fd2646865a0023e04be4967e712c02/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/81d323846d11ab383afd98a34aef5feff5fd2646865a0023e04be4967e712c02/hostname",
"HostsPath": "/var/lib/docker/containers/81d323846d11ab383afd98a34aef5feff5fd2646865a0023e04be4967e712c02/hosts",
"LogPath": "/var/lib/docker/containers/81d323846d11ab383afd98a34aef5feff5fd2646865a0023e04be4967e712c02/81d323846d11ab383afd98a34aef5feff5fd2646865a0023e04be4967e712c02-json.log",
"Name": "/sad_dewdney",
"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/13a9b348dcb7ec84dae8e3cc6766c8d284ac9f45ca4cc3af341a9e1381131f0e-init/diff:/var/lib/docker/overlay2/ceeaa5c3fbacd569a80e013cd1a6b907befa0d99540989b93b8815c9bf1451bb/diff",
"MergedDir": "/var/lib/docker/overlay2/13a9b348dcb7ec84dae8e3cc6766c8d284ac9f45ca4cc3af341a9e1381131f0e/merged",
"UpperDir": "/var/lib/docker/overlay2/13a9b348dcb7ec84dae8e3cc6766c8d284ac9f45ca4cc3af341a9e1381131f0e/diff",
"WorkDir": "/var/lib/docker/overlay2/13a9b348dcb7ec84dae8e3cc6766c8d284ac9f45ca4cc3af341a9e1381131f0e/work"
},
"Name": "overlay2"
},
"Mounts": [],
"Config": {
"Hostname": "81d323846d11",
"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": "23b5413c3d4ff11d5cb5b1d93acd35c3132ca7e5183fc178179f89436b0dda23",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {},
"SandboxKey": "/var/run/docker/netns/23b5413c3d4f",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "e834842300b4afe5cbf75789ec9e534acc1d62235e9efd0cbd305dbcf9c8e488",
"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": "603e3599e40881a802fb09405c7bb535241e86cd1ae9671bad557dead6b9a31b",
"EndpointID": "e834842300b4afe5cbf75789ec9e534acc1d62235e9efd0cbd305dbcf9c8e488",
"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
}
}
}
}
]
|