帮助命令
docker version 显示docker的版本信息
docker info 显示docker的系统信息
docker help 显示docker的参数
Docker的官方文档:
查看当前镜像
[root@lin ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest bf756fb1ae65 13 months ago 13.3kB
#解释:
REPOSITORY 镜像的仓库源
Tag 标签
IMAGE ID 镜像ID
CREATED 创建时间
SIZE 大小
#可选项
[root@lin ~]# docker images --help
-a,--all 查看所有镜像
[root@lin ~]# docker search MysqL
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
MysqL MysqL is a widely used,open-source relation… 10466 [OK]
指定版本下载
[root@lin ~]# docker pull MysqL:5.7 5.7: Pulling from library/MysqL a076a628af6f: Already exists f6c208f3f991: Already exists 88a9455a9165: Already exists 406c9b8427c6: Already exists 7c88599c0b25: Already exists 25b5c6debdaf: Already exists 43a5816f1617: Already exists 1831ac1245f4: Pull complete 37677b8c1f79: Pull complete 27e4ac3b0f6e: Pull complete 7227baa8c445: Pull complete Digest: sha256:b3d1eff023f698cd433695c9506171f0d08a8f92a0c8063c1a4d9db9a55808df Status: Downloaded newer image for MysqL:5.7 docker.io/library/MysqL: # docker pull MysqL 等于 docker.io/library/MysqL:latest
导出镜像 and 导入镜像
#导出 docker save -o busyBox.tar busyBox:latest 或 docker save > busyBox01. busyBox:latest #导入 docker load -i busyBox. 或 docker load < busyBox. ###### PS:这里使用带参数的命令导出,尽量使用对于带参数的命令导入
我们下载一个centos镜像
docker pull centos
docker create -it --name test busyBox:latest sh
新建容器并启动
docker run 【可选参数】 images 参数: --name=xx : 容器名称 -d: 后台运行 -it: 交互方式,伪终端 -p: 指定容器端口 8080主机端:8080容器段 -p 容器端口 -P: 随机映射端口 #创建一台名称为a1的centos主机,登录使用sh命令 [root@lin ~]# docker run -itd --name a1 centos:latest sh 4584d81270ea66ddaf1663db158f482865be63c6f4b187ae8ea94a2b42769bd8 [root@lin ~]# docker exec -it a1 sh sh-4.4# ls bin etc lib lost+found mnt proc run srv tmp var dev home lib64 media opt root sbin sys usr 4.4# exit #退出容器Ctrl+d也可以 exit [root@lin ~]#
查看容器
#docker ps命令 参数: -a 当前所有容器 -n 1 显示最近创建的几个,默认显示1 -q 显示ID -s 显示大小 [root@lin ~]# docker ps #查看正在运行的容器 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4584d81270ea centos:latest "sh" 2 minutes ago Up 2 minutes a1 [root@lin ~]# docker ps -as CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES SIZE 4584d81270ea centos:latest 7 minutes ago Up 7 minutes a1 14B (virtual 209MB) 94082dde1104 centos bash" 11 minutes ago Exited (0) minutes ago recursing_aryabhata 0B (virtual 209MB) 81e87e0dddcb bf756fb1ae65 /hello" 2 hours ago Exited (2 hours ago happy_ramanujan 0B (virtual 13.3kB)
删除容器
docker rm 容器ID 删除容器,不能删除在运行中的容器,如果需要删除 -f强制 docker rm -f $(docker aq) 删除所有容器 docker rm -aq | axrgs docker rm -f 删除所有容器
启动容器 and 停止容器
docker stop ID #启动 docker restart ID #重启 docker stop ID #停止 docker kill ID #杀死
将容器制作成镜像
docker run -itd --name centos centos:8 docker exec -it centos yum -y install Nginx 4.4# Nginx ef UID PID PPID C STIME TTY TIME CMD root 1 0 0 13:51 pts/0 00:00 root 12 54 pts/1 root 110 55 ? 00 Nginx: master process Nginx 4.4# curl 127.0.0.1 <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.1//EN" http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns=http://www.w3.org/1999/xhtml" xml:lang=en"> <head> <title>Test Page for the Nginx HTTP Server on Red Hat Enterprise Linux</title> # exit [root@lin ~]# docker commit -m 'ng' -a lin' centos centos.Nginx. sha256:9b8912f7716ae063f96f996611b752e7a6b6286a00b614cc0667fd358025b4e4 -m:描述 -a:作者 容器名称 镜像名称
docker日志的查看
[root@lin ~]# docker logs a1 # exit # exit #常用参数 -f,--follow #显示日志 -t,1)">timestamps #显示时间戳 [root@lin ~]# docker logs -ft a1 2021-02-05T04:01:35.128760582Z # exit 41.500899867Z 51.404994752Z # exit #查看一行 [root@lin ~]# docker logs -ft --tail a1 4.4# exit
docker进程的查看
[root@lin ~]# docker top 897 UID PID PPID C STIME TTY TIME CMD root 74091 74075 0 16:30 pts/0 00 sh
docekr元数据的查看
#查看docker容器a1的元数据 [root@lin ~]# docker inspect a1 [ { Id": 66fa2e853870af06f32c166c6c75280db4d728c31502ca63bc848dfc96d613a6",Created2021-02-05T04:01:20.073183239ZPathArgs: [],1)">State: { StatusexitedRunning": falsePausedRestartingOOMKilledDeadPid0ExitCodeError""StartedAt2021-02-05T04:01:41.846430128ZFinishedAt2021-02-05T04:01:51.405660547Z },1)">Imagesha256:300e315adb2f96afe5f0b2780b87f28ae95231fe3bdd1e16b9ba606307728f55ResolvConfPath/var/lib/docker/containers/66fa2e853870af06f32c166c6c75280db4d728c31502ca63bc848dfc96d613a6/resolv.confHostnamePath/var/lib/docker/containers/66fa2e853870af06f32c166c6c75280db4d728c31502ca63bc848dfc96d613a6/hostnameHostsPath/var/lib/docker/containers/66fa2e853870af06f32c166c6c75280db4d728c31502ca63bc848dfc96d613a6/hostsLogPath/var/lib/docker/containers/66fa2e853870af06f32c166c6c75280db4d728c31502ca63bc848dfc96d613a6/66fa2e853870af06f32c166c6c75280db4d728c31502ca63bc848dfc96d613a6-json.logName/a1RestartCountDriveroverlay2PlatformlinuxMountLabelProcessLabelAppArmorProfileExecIDsnullHostConfigBindsContainerIDFileLogConfig: { Typejson-fileConfig: {} },1)">NetworkModedefaultPortBindings: {},1)">RestartPolicynoMaximumRetryCount },1)">AutoRemoveVolumeDriverVolumesFromCapAddCapDropCapabilitiesDnsDnsOptionsDnsSearchExtraHostsGroupAddIpcModeprivateCgroupLinksOomscoreAdjPidModePrivilegedPublishAllPortsReadonlyRootfsSecurityOptUTSModeUsernsModeShmSize67108864RuntimeruncConsoleSize: [ ],1)">IsolationcpuSharesMemoryNanocpusCgroupParentBlkioWeightBlkioWeightDeviceBlkioDeviceReadBpsBlkioDeviceWriteBpsBlkioDeviceReadiopsBlkioDeviceWriteIOpscpuPeriodcpuQuotacpuRealtimePeriodcpuRealtimeRuntimecpusetcpuscpusetMemsDevicesDeviceCgroupRulesDeviceRequestsKernelMemoryKernelMemoryTCPMemoryReservationMemorySwapMemorySwappinessOomKillDisablePidsLimitUlimitscpuCountcpuPercentIOMaximumIOpsIOMaximumBandwidthMaskedPaths/proc/asound/proc/acpi/proc/kcore/proc/keys/proc/latency_stats/proc/timer_list/proc/timer_stats/proc/sched_debug/proc/scsi/sys/firmwareReadonlyPaths/proc/bus/proc/fs/proc/irq/proc/sys/proc/sysrq-trigger ] },1)">GraphDriverDataLowerDir/var/lib/docker/overlay2/ecf96d9788e18375d3db3cb0f6f476bba8af71fc1101b44e4ec84962cbb3734e-init/diff:/var/lib/docker/overlay2/5ead7fb0234a638b1f4c8ece5572cd7e34d0e7b410face8bc0c83a670cd92736/diffMergedDir/var/lib/docker/overlay2/ecf96d9788e18375d3db3cb0f6f476bba8af71fc1101b44e4ec84962cbb3734e/mergedUpperDir/var/lib/docker/overlay2/ecf96d9788e18375d3db3cb0f6f476bba8af71fc1101b44e4ec84962cbb3734e/diffWorkDir/var/lib/docker/overlay2/ecf96d9788e18375d3db3cb0f6f476bba8af71fc1101b44e4ec84962cbb3734e/workMountsHostname66fa2e853870DomainnameUserAttachStdinAttachStdoutAttachStderrTtytrueOpenStdinStdinOnceEnvPATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/binCmdcentosVolumesWorkingDirEntrypointOnBuildLabelsorg.label-schema.build-date20201204org.label-schema.licenseGPLv2org.label-schema.nameCentOS Base Imageorg.label-schema.schema-version1.0org.label-schema.vendorCentOS } },1)">NetworkSettingsBridgeSandBoxID836ea0ff6c93e7f368b31917f27dcf79d7f00e02f6821e13f750697f0c262eb5HairpinModeLinkLocalIPv6AddressLinkLocalIPv6PrefixLenPortsSandBoxKey/var/run/docker/netns/836ea0ff6c93SecondaryIPAddressesSecondaryIPv6AddressesEndpointIDGatewayGlobalIPv6AddressGlobalIPv6PrefixLenIPAddressIPPrefixLenIPv6GatewayMacAddressNetworksbridge: { IPAMConfigAliasesNetworkID2ca8ec3eb55c3034230866255d65f988376c95ddf492a9a074b4fd60b94eb594DriverOpts } } } } ]
进入当前正在运行的容器
方式一: [root@lin ~]# docker exec -it a2 #解释: #-i: 交互式 #-t: 伪终端 08:30 pts/ root 6 39 pts/6 ef 方式二: [root@lin ~]# docker attach a2 found mnt proc run srv tmp var dev home lib64 media opt root sbin sys usr #区别 #docekr exec 进入容器开启新的终端 #docker attach 相当于直接进入容器
从容器内拷贝文件到主机上
docker cp 容器ID:容器内路径 目的的主机路径 [root@lin /]# docker exec -it a3 4.4# cd /home/ touch index.html # exit [root@lin /]# docker cp a3:/home/index.html /test [root@lin /]# ls /test/ index.html
如果能看懂下面的图片,说明您的知识点很不错的呦~
原文链接:/docker/997441.html