docker详细
镜像(image)
容器(container) 启动,删除,停止
仓库(repository)
docker images
docker images -a 列出全部
docker images -q 只显示镜像id
docker search 搜索镜像
搜索收藏大于3000的... docker search mysql -f=STARS=3000
docker pull 下载镜像
如果不写tag默认就是latest,下载是分层下载
删除镜像 docker rmi 镜像
新建容器并启动:
docker run
参数:
--name="name" 容器名称 tomcat1 tomcat2 区分容器
-d 后台方式运行
-it 使用交互方式运行,进入容器内部查看内容
-p 指定容器端口 -p 8080:8080
-p ip:主机端口:容器端口
-p 主机端口:容器端口
-p 容器端口
-p (不指定端口就随机端口了啊)
比如这个就是启动并且进入容器内部
docker run -it centos /bin/bash
退出容器:exit(退出就停止了)
xtel+P+Q 不停止退出
查看正在运行的容器docker ps
docker ps -a -n=1 列出正在运行的容器+历史运行过容器
-n 最近创建的容器
docker ps -aq {-q}显示容器编号
删除容器:
docker rm 容器id 删除指定容器正在运行则删除失败
docker rm -f 删除所有容器
docker ps -a -q |xargs docker rm 删除所有容器
启动和停止的容器操作
docker start 容器id
docker restart 容器id
docker stop 容器id
docker kill 容器id
后台启动容器后-d
发现容器停止了,容器后台启动必须有后台进程,发现没有后台进程会自动停止
编写shell脚本输出日志
docker run -d centos /bin/sh -c "while true;do echo kuang;sleep 1;done"
查看日志 docker logs -tf --tail 10 d1c5d0984801
备注:
-tf 显示日志
--tail 【number】 显示日志条数
显示容器进程信息
docker top 容器id
查看镜像元数据
docker inspect d1c5d0984801
[
{
"Id": "d1c5d0984801509d224689cecae9209e05b7db39f409abf92697c93243f15c30",
"Created": "2020-12-26T06:55:51.1766263Z",
"Path": "/bin/sh",
"Args": [
"-c",
"while true;do echo kuang;sleep 1;done"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 1940,
"ExitCode": 0,
"Error": "",
"StartedAt": "2020-12-26T06:55:51.4081217Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:300e315adb2f96afe5f0b2780b87f28ae95231fe3bdd1e16b9ba606307728f55",
"ResolvConfPath": "/var/lib/docker/containers/d1c5d0984801509d224689cecae9209e05b7db39f409abf92697c93243f15c30/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/d1c5d0984801509d224689cecae9209e05b7db39f409abf92697c93243f15c30/hostname",
"HostsPath": "/var/lib/docker/containers/d1c5d0984801509d224689cecae9209e05b7db39f409abf92697c93243f15c30/hosts",
"LogPath": "/var/lib/docker/containers/d1c5d0984801509d224689cecae9209e05b7db39f409abf92697c93243f15c30/d1c5d0984801509d224689cecae9209e05b7db39f409abf92697c93243f15c30-json.log",
"Name": "/epic_borg",
"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": [
30,
120
],
"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/c97e321fc77c00debc8f56a525efb4c3f0dd462908106dfef38c4dcfd4018857-init/diff:/var/lib/docker/overlay2/e28f2d567373fa7779b1e240041f792393c4e060812a74bc76582eb31262fe17/diff",
"MergedDir": "/var/lib/docker/overlay2/c97e321fc77c00debc8f56a525efb4c3f0dd462908106dfef38c4dcfd4018857/merged",
"UpperDir": "/var/lib/docker/overlay2/c97e321fc77c00debc8f56a525efb4c3f0dd462908106dfef38c4dcfd4018857/diff",
"WorkDir": "/var/lib/docker/overlay2/c97e321fc77c00debc8f56a525efb4c3f0dd462908106dfef38c4dcfd4018857/work"
},
"Name": "overlay2"
},
"Mounts": [],
"Config": {
"Hostname": "d1c5d0984801",
"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 kuang;sleep 1;done"
],
"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": "72c9fd18a54275d1be0acb121edb1503ae3f67e2778ae1f2ae29ed30ad008ab3",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {},
"SandboxKey": "/var/run/docker/netns/72c9fd18a542",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "da881795328917da6fb33e3c05ae3cabe69bb7ca4ee1321275dd0f46adc98a8b",
"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": "146f4611158b176bf6440c672c34d3ab9effa03e79cc745ecbeaf89a01490bc4",
"EndpointID": "da881795328917da6fb33e3c05ae3cabe69bb7ca4ee1321275dd0f46adc98a8b",
"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
}
}
}
}
]
进入容器的两种方式:
docker attach 容器id 进入正在执行的容器,不会启动新终端。
docker exec 进入容器后开启一个新的终端.
从容器内拷贝文件到主机上
docker cp 容器id 容器内路径 目的主机路径
数据从容器内部拷出到win10: docker cp bc81713669cf:/var/log F:/docker_data/lib
数据将从win10 拷进 docker
docker cp F:/docker_data/newdata bc81713669cf:/home
小总结:
attach:当前shell下attach连接指定运行镜像
build:通过dockerfile定制镜像
commit:提交当前容器作为新的镜像
cp:从容器中拷贝指定文件或目录到宿主机器中
create:创建一个新容纳国企但不启动容器
diff:查看docker容器变化
events:从docker服务获取容器实时事件
exec:进入已存在的容器,不启动新窗口
export:导出容器的内容流作为一个tar归档文件[对应imoprt]
history:展示一个镜像形成历史
images:列出系统当前镜像
import:从tar包中的内容创建一个新的文件系统
info:展示系统相关信息
inspect:查看容器详细信息
kill:杀死指定kill容器
load:从一个tar包中加载一个镜像
login:登录docker服务账号
logs:输出日志信息
logout:退出
port:查看映射端口对应的容器内部源端
pause:暂停容器
ps:列出容器列表
pull:从源拉取指定镜像
push:推送指定镜像
restart:从其运行的容器
rm:移除容器
rmi:移除镜像
run :创建一个新容器并启动
save:保存镜像
search:搜索镜像
start:启动镜像
stop:停止镜像
tag:给镜像打标签
top:查看镜像进程
unpause:取消暂停镜像
version:看版本
wait:截取容器停止时的退出状态值
---------------------------------------------------------------------------
国之殇,未敢忘!
南京大屠杀!
731部队!
(有关书籍《恶魔的饱食》)以及核污染水排海等一系列全无人性的操作,购买他们的食品和为它们提供帮助只会更加变本加厉的害你,呼吁大家不要购买日本相关产品
昭昭前事,惕惕后人
吾辈当自强,方使国不受他人之侮!
---------------------------------------------------------------------------
作者:三号小玩家
出处:https://www.cnblogs.com/q1359720840/
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。 版权信息