(1).基本使用方法
查看所有镜像。docker images
[[email protected] ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE centos httpd 65f64a254fcc 18 hours ago 346MB ghhh4512/centos httpd 565f0e4e1ef3 19 hours ago 346MB centos latest 67fa590cfc1c 3 weeks ago 202MB hub.c.163.com/library/tomcat latest 72d2be374029 2 years ago 292MB
启动一个实例,并在实例中执行/bin/bash命令。docker run -it [镜像] [命令],run表示运行,-i选项表示以交互模式运行容器(通常与-t选项同时使用),-t选项表示为容器分配一个伪终端,[镜像]可以是镜像ID也可以是[仓库名]:[标签名]。
[[email protected] ~]# docker run -it centos:latest /bin/bash [[email protected] /]# exit //注意它们的容器实例名称不同 exit [[email protected] ~]# docker run -it 67fa590cfc1c /bin/bash [[email protected] /]# exit exit
在后台运行一个命令,模拟后台运行服务。docker run -d [镜像] [命令] -c [待执行命令],-d选项表示后台运行容器,-c选项后跟随待执行的命令
[[email protected] ~]# docker run -d centos:latest /bin/sh -c "while true;do echo hello world;sleep 1;done" f8ed8003fe20965a2d358af0f3c19b56f81b664385f2a0bbe3d643e91271eb60 //容器实例ID
从容器中读取日志,查看输入内容,可用于查询docker实例在标准输出中显示的错误信息和正常信息。docker logs [容器实例ID],容器实例ID可以只截取一部分。
[[email protected] ~]# docker logs f8ed8003fe hello world hello world hello world hello world hello world hello world
查看正在运行的容器。docker ps
[[email protected] ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f8ed8003fe20 centos:latest "/bin/sh -c ‘while t…" 3 minutes ago Up 3 minutes objective_dubinsky
停止一个容器实例。docker stop [容器实例ID]
[[email protected] ~]# docker stop f8ed8003fe20 f8ed8003fe20 [[email protected] ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
如果一个容器实例无法停止,那么还可以使用命令杀死该容器实例。docker kill [容器实例ID]
[[email protected] ~]# docker run -d centos:latest /bin/sh -c "while true;do echo hello world;sleep 1;done" 72217237c3121fba16275490344c5168530d8c0f65d3f22ec0e53c5de4ed0887 [[email protected] ~]# docker kill 72217237c3 72217237c3 [[email protected] ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
查看所有容器,包括退出状态的容器。docker ps -a
[[email protected] ~]# docker ps -a //第一个是被kill掉的容器实例,第二个是被stop掉的容器实例 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 72217237c312 centos:latest "/bin/sh -c ‘while t…" 45 seconds ago Exited (137) 31 seconds ago eager_kalam f8ed8003fe20 centos:latest "/bin/sh -c ‘while t…" 11 minutes ago Exited (137) 5 minutes ago objective_dubinsky 5ab4fae39b65 67fa590cfc1c "/bin/bash" 35 minutes ago Exited (0) 35 minutes ago strange_euclid 280414ba684e centos:latest "/bin/bash" 35 minutes ago Exited (0) 35 minutes ago ecstatic_napier 92c1d60be419 centos:httpd "/bin/sh -c /usr/loc…" 18 hours ago Exited (137) 18 hours ago jovial_chebyshev 985ef7e0c4ca centos:latest "/bin/bash" 22 hours ago Exited (0) 22 hours ago sharp_kare 9a81af9b4134 centos:latest "/bin/bash" 3 days ago Exited (0) 3 days ago pensive_dijkstra 3ecc9bafd429 centos:latest "/bin/bash" 3 days ago Exited (0) 3 days ago sleepy_wilbur
还可以使用命令,使得这些实例再次启动。docker start [容器实例ID];docker restart [容器实例ID]。
[[email protected] ~]# docker start 72217237c312 72217237c312 [[email protected] ~]# docker restart f8ed8003fe20 f8ed8003fe20 [[email protected] ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 72217237c312 centos:latest "/bin/sh -c ‘while t…" 9 minutes ago Up 15 seconds eager_kalam f8ed8003fe20 centos:latest "/bin/sh -c ‘while t…" 19 minutes ago Up 2 seconds objective_dubinsky
删除容器实例。docker rm [容器实例],如果正在运行,可以停止或杀死实例再删除,也可以加上-f选项强制删除。
[[email protected] ~]# docker kill 72217237c312 72217237c312 [[email protected] ~]# docker rm 72217237c312 72217237c312 [[email protected] ~]# docker rm -f f8ed8003fe20 f8ed8003fe20 [[email protected] ~]# docker ps -a//可以看到已经没有删除的容器实例了 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5ab4fae39b65 67fa590cfc1c "/bin/bash" 46 minutes ago Exited (0) 46 minutes ago strange_euclid 280414ba684e centos:latest "/bin/bash" 46 minutes ago Exited (0) 46 minutes ago ecstatic_napier 92c1d60be419 centos:httpd "/bin/sh -c /usr/loc…" 18 hours ago Exited (137) 18 hours ago jovial_chebyshev 985ef7e0c4ca centos:latest "/bin/bash" 22 hours ago Exited (0) 22 hours ago sharp_kare 9a81af9b4134 centos:latest "/bin/bash" 3 days ago Exited (0) 3 days ago pensive_dijkstra 3ecc9bafd429 centos:latest "/bin/bash" 3 days ago Exited (0) 3 days ago sleepy_wilbur
删除镜像。docker rmi [镜像],如果存在实例(包括沉睡和停止),那么可以先删除实例再删除镜像,也可以使用-f选项强制删除。
[[email protected] ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE centos httpd 65f64a254fcc 19 hours ago 346MB ghhh4512/centos httpd 565f0e4e1ef3 20 hours ago 346MB centos latest 67fa590cfc1c 3 weeks ago 202MB hub.c.163.com/library/tomcat latest 72d2be374029 2 years ago 292MB [[email protected] ~]# docker run -it ghhh4512/centos:httpd /bin/bash [[email protected] /]# exit exit [[email protected] ~]# docker ps -a //可以看到ghhh4512/centos:httpd镜像存在一个实例 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1b7f3ac5f4c7 ghhh4512/centos:httpd "/bin/bash" 8 seconds ago Exited (0) 5 seconds ago peaceful_elbakyan 5ab4fae39b65 67fa590cfc1c "/bin/bash" About an hour ago Exited (0) About an hour ago strange_euclid 280414ba684e centos:latest "/bin/bash" About an hour ago Exited (0) About an hour ago ecstatic_napier 92c1d60be419 centos:httpd "/bin/sh -c /usr/loc…" 19 hours ago Exited (137) 18 hours ago jovial_chebyshev 985ef7e0c4ca centos:latest "/bin/bash" 22 hours ago Exited (0) 22 hours ago sharp_kare 9a81af9b4134 centos:latest "/bin/bash" 3 days ago Exited (0) 3 days ago pensive_dijkstra 3ecc9bafd429 centos:latest "/bin/bash" 3 days ago Exited (0) 3 days ago sleepy_wilbur [[email protected] ~]# docker rmi ghhh4512/centos:httpd //直接删除会报错 Error response from daemon: conflict: unable to remove repository reference "ghhh4512/centos:httpd" (must force) - container 1b7f3ac5f4c7 is using its referenced image 565f0e4e1ef3 [[email protected] ~]# docker rmi -f ghhh4512/centos:httpd //强制删除 Untagged: ghhh4512/centos:httpd Untagged: ghhh4512/[email protected]:464ffb58cbc2334a936bea7081db41b257afb5b21dfcce6dd27863dc9b777855 Deleted: sha256:565f0e4e1ef37c6b4100bda2266bb5aabfbc74d74d571f97b7448eafba89038f Deleted: sha256:277a40438987a596dd86eb7b1d565ad733d4b809616b415d6235d242de56b89c Deleted: sha256:bea321c82f68d3c2d62daf5295078805180c56688ad7fc4e6b8b32f2dfa9b586 [[email protected] ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE centos httpd 65f64a254fcc 19 hours ago 346MB centos latest 67fa590cfc1c 3 weeks ago 202MB hub.c.163.com/library/tomcat latest 72d2be374029 2 years ago 292MB [[email protected] ~]# docker ps -a//相应的实例也被删除 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 1b7f3ac5f4c7 565f0e4e1ef3 "/bin/bash" 2 minutes ago Exited (0) 2 minutes ago peaceful_elbakyan 5ab4fae39b65 67fa590cfc1c "/bin/bash" About an hour ago Exited (0) About an hour ago strange_euclid 280414ba684e centos:latest "/bin/bash" About an hour ago Exited (0) About an hour ago ecstatic_napier 92c1d60be419 centos:httpd "/bin/sh -c /usr/loc…" 19 hours ago Exited (137) 19 hours ago jovial_chebyshev 985ef7e0c4ca centos:latest "/bin/bash" 22 hours ago Exited (0) 22 hours ago sharp_kare 9a81af9b4134 centos:latest "/bin/bash" 3 days ago Exited (0) 3 days ago pensive_dijkstra 3ecc9bafd429 centos:latest "/bin/bash" 3 days ago Exited (0) 3 days ago sleepy_wilbur
(2).容器实例的命名和重命名
容器实例的命名,就是在运行时使用--name [容器实例ID名]选项。如下:
[[email protected] ~]# docker run -itd --name docker1 centos:latest /bin/bash 118da4c24c2e02632449a5124f32401ed4332aaa91aece52222aca9e757fe1c5 [[email protected] ~]# docker run -itd centos:latest /bin/bash 14934f6eb3db8d2d80585e7ae7488418b4d360dd71547c62f4d392b1327ddcdb [[email protected] ~]# docker ps//可以看到两个容器实例名称的对比 CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 14934f6eb3db centos:latest "/bin/bash" 4 seconds ago Up 3 seconds wizardly_engelbart 118da4c24c2e centos:latest "/bin/bash" 58 seconds ago Up 57 seconds docker1
容器实例的重命名。docker rename [旧的容器实例名] [新的容器实例名]。如下:
[[email protected] ~]# docker rename docker1 docker2 [[email protected] ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 14934f6eb3db centos:latest "/bin/bash" 3 minutes ago Up 3 minutes wizardly_engelbart 118da4c24c2e centos:latest "/bin/bash" 4 minutes ago Up 4 minutes docker2
容器实例的命名可以方便我们调用该容器实例
[[email protected] ~]# docker stop docker2 docker2 [[email protected] ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 14934f6eb3db centos:latest "/bin/bash" 6 minutes ago Up 6 minutes wizardly_engelbart [[email protected] ~]# docker kill 14934f6eb3db 14934f6eb3db
(3).创建容器实例时指定容器的主机名
指定容器实例的主机名,其实就是在启动容器实例时使用的是-h [主机名]选项。如下:
[[email protected] ~]# docker run -it -h youxi centos:latest /bin/bash [[email protected] /]# hostname youxi [[email protected] /]# exit exit
(4).让容器实例随docker服务的启动而启动
让容器实例跟随docker服务启动而启动,其实就是在启动容器实例时使用--restart=[参数]来调整重启策略。参数可以是:no,默认策略,在容器退出时不重启容器;no-failure,在容器正常退出时(退出状态非0),才会重启容器;no-failure:3,在容器非正常退出时重启容器,最多3次;always,在容器退出时总是重启容器;unless-stopped,在容器退出时总是重启,但不考虑Docker守护进程启动时就已经停止的容器。
对比always和unless-stopped,如下:
//使用always参数 [[email protected] ~]# docker run --restart=always -itd --name always-docker centos:latest bash d02e6e2587e9933f9535e70b94d69385c686f225afb6c59913f796124dd9a2c6 //使用unless-stopped参数 [[email protected] ~]# docker run --restart=unless-stopped -itd --name unless-stopped-docker centos:latest bash cfcfe9495d17585e388af27681a5f8234fbba5beca7b3a469156875ddd9ee6f2 [[email protected] ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d02e6e2587e9 centos:latest "bash" 6 seconds ago Up 4 seconds always-docker cfcfe9495d17 centos:latest "bash" 8 seconds ago Up 7 seconds unless-stopped-docker //重启docker服务没有差别 [[email protected] ~]# systemctl restart docker [[email protected] ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES cfcfe9495d17 centos:latest "bash" 36 seconds ago Up 2 seconds unless-stopped-docker d02e6e2587e9 centos:latest "bash" 7 minutes ago Up 2 seconds always-docker //重启系统没有差别 [[email protected] ~]# init 6 ......//等待重启 [[email protected] ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES cfcfe9495d17 centos:latest "bash" 3 minutes ago Up 55 seconds unless-stopped-docker d02e6e2587e9 centos:latest "bash" 10 minutes ago Up 55 seconds always-docker //停止容器实例,出现了差别。unless-stopped参数的容器实例不启动了 [[email protected] ~]# docker stop always-docker always-docker [[email protected] ~]# docker stop unless-stopped-docker unless-stopped-docker [[email protected] ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES [[email protected] ~]# systemctl restart docker [[email protected] ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d02e6e2587e9 centos:latest "bash" 12 minutes ago Up 1 second always-docker [[email protected]uxi1 ~]# init 6 [[email protected] ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d02e6e2587e9 centos:latest "bash" 32 minutes ago Up 9 minutes always-docker
更新容器实例的重启策略。docker update --restart=[参数] [容器实例ID或名称]
[[email protected] ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d02e6e2587e9 centos:latest "bash" 32 minutes ago Up 9 minutes always-docker [[email protected] ~]# docker update --restart=no always-docker always-docker [[email protected] ~]# systemctl restart docker [[email protected] ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
(5).docker数据映射
docker数据映射是指将物理机的本地目录映射到容器实例中,是在运行时使用-v [物理机本地目录]:[容器实例内部目录]。如下:
[[email protected] ~]# mkdir -p /var/www/html [[email protected] ~]# echo aaaa > /var/www/html/a.html [[email protected] ~]# docker run -it -v /var/www/html:/var/www/html centos:httpd bash [[email protected] /]# ls /var/www/html/ a.html
这样做的好处是,即使docker坏了,数据还是在物理机上,不会丢失。
另外还有类似的--device [物理机设备地址]:[容器实例中的设备地址]设备对设备映射。
(6).容器资源配额控制
在最开始时就已经说过Docker通过cgroup控制容器使用的资源配额,包括CPU、内存、磁盘三大方面,基本覆盖了常见的资源配额和使用量控制。
cgroup是Control Groups的缩写,是Linux内核提供的一种可以限制、记录、隔离进程组所使用的物理资源(如cpu、memory、磁盘IO等)的机制,被LXC、docker等很多项目用于实现进程资源控制。cgroup将任意进程进行分组化管理的Linux内核功能。 cgroup本身是提供将进程进行分组化管理的功能和接口基础结构,I/O或内存的分配控制等具体的资源管理功能是通过这个功能来实现的。
进行硬件配额是为了防止在多个容器实例同时运行时,某个容器实例把所有硬件资源占满(比如被黑的容器实例)。
1)CPU
指定容器使用的CPU份额,使用的是-c, --cpu-shares [整数]选项,这里的整数值是一个加权值(类似比列),并不是固定份额。默认docker容器实例的cpu份额值都是1024,容器实例A设定--cpu-shares 1000,容器实例B设定--cpu-shares 500,容器实例A和B的总和是超过1024的,但并没有关系,如果两个容器实例同时跑到极限(争抢一个CPU资源),那么容器实例A所占的CPU份额是容器实例B的两倍。
[[email protected] ~]# docker run -it --cpu-shares 512 centos:latest bash [[email protected] /]# cat /sys/fs/cgroup/cpu/cpu.shares 512
对于多核CPU的服务器,docker还可以控制容器实例限定使用的CPU内核和内存节点,即--cpuset-cpus和--cpuset-mems,对具有NUMA拓扑(具有多CPU、多内存节点)的服务器尤其有用,可以对需要高性能计算的容器实例进行性能最优的配置。如果服务器只有一个内存节点,则--cpuset-mems的配置基本不会有明显效果。
将进程绑定到CPU上是为了减少CPU上下文切换的开销,节约时间。
扩展:对称多处理器结构(SMP:Symmetric Multi-Processor) ,例:x86服务器,双路服务器,主板上有两个物理cpu;非一致存储访问结构(NUMA:Non-Uniform Memory Access), 例:IBM小型机pSeries 690;海量并行处理结构 (MPP : Massive ParallelProcessing), 例: 大型机。
[[email protected] ~]# docker run -it --cpuset-cpus 0-2 centos:latest bash [[email protected]78351ad3d /]# taskset -cp 1 pid 1‘s current affinity list: 0-2
混合使用实验(需要打开三个窗口),如下:
//第一个窗口,docker容器实例绑定CPU核心0和1,CPU份额权重设置为512 [[email protected] ~]# docker run -it -h docker1 --cpuset-cpus 0-1 --cpu-shares 512 centos:latest bash [[email protected] /]# yum -y install epel-release [[email protected] /]# yum -y install stress //安装压力测试工具 //第二个窗口,docker容器实例绑定CPU核心0和1,CPU份额权重设置为1024 [[email protected] ~]# docker run -it -h docker2 --cpuset-cpus 0-1 --cpu-shares 1024 centos:latest bash [[email protected] /]# yum -y install epel-release [[email protected] /]# yum -y install stress //安装压力测试工具 //第三个窗口 [[email protected] ~]# top //按下1和c,是CPU核心展开,并且下方按CPU占用排序 //首先测试,--cpu-shares选项是否会阻止容器实例占据CPU所有份额。在第一个窗口使用压力测试名 [[email protected] /]# stress -c 2 --verbose --timeout 20s //开始执行后立即到第三个窗口查看,可以看到Cpu0和Cpu1都达到了百分百,并且是两个stress也达到了百分百。 top - 16:57:27 up 1:55, 3 users, load average: 2.08, 1.41, 0.68 Tasks: 193 total, 3 running, 190 sleeping, 0 stopped, 0 zombie %Cpu0 :100.0 us, 0.0 sy, 0.0 ni, 0.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st %Cpu1 :100.0 us, 0.0 sy, 0.0 ni, 0.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st %Cpu2 : 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st %Cpu3 : 0.3 us, 0.0 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 2030172 total, 677712 free, 339108 used, 1013352 buff/cache KiB Swap: 2097148 total, 2097148 free, 0 used. 1457364 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 3983 root 20 0 7308 100 0 R 100.0 0.0 0:05.83 stress -c+ 3984 root 20 0 7308 100 0 R 100.0 0.0 0:05.83 stress -c+ 775 root 20 0 21672 1300 972 S 0.3 0.1 0:02.37 /usr/sbin+ 3965 root 20 0 162104 2372 1588 R 0.3 0.1 0:00.38 top 1 root 20 0 191008 4000 2604 S 0.0 0.2 0:02.79 /usr/lib/+ //测试当两个容器实例争抢CPU资源时,是否是1:2的情况 //第一个窗口 [[email protected] /]# stress -c 2 --verbose --timeout 20s //第二个窗口 [[email protected] /]# stress -c 2 --verbose --timeout 20s //立即到第三个窗口查看,可以看到Cpu0和Cpu1都达到百分百,四个stressCPU比为2:2:1:1, //其中两个66.8是CPU份额权重为1024的容器实例,33.2是CPU份额权重为512的容器实例。 top - 16:58:36 up 1:56, 3 users, load average: 1.14, 1.27, 0.68 Tasks: 196 total, 5 running, 191 sleeping, 0 stopped, 0 zombie %Cpu0 :100.0 us, 0.0 sy, 0.0 ni, 0.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st %Cpu1 :100.0 us, 0.0 sy, 0.0 ni, 0.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st %Cpu2 : 0.0 us, 0.3 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st %Cpu3 : 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st KiB Mem : 2030172 total, 677468 free, 339296 used, 1013408 buff/cache KiB Swap: 2097148 total, 2097148 free, 0 used. 1457124 avail Mem PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 3990 root 20 0 7308 96 0 R 66.8 0.0 0:02.98 stress -c+ 3991 root 20 0 7308 96 0 R 66.8 0.0 0:02.97 stress -c+ 3987 root 20 0 7308 100 0 R 33.2 0.0 0:02.60 stress -c+ 3988 root 20 0 7308 100 0 R 33.2 0.0 0:02.73 stress -c+ 3965 root 20 0 162104 2372 1588 R 0.3 0.1 0:00.64 top 1 root 20 0 191008 4000 2604 S 0.0 0.2 0:02.79 /usr/lib/+
由以上实验可得出结论:在没有CPU资源争抢的情况下,CPU份额权重(--cpu-shares)并不会生效。一旦发生CPU资源争抢的情况,将会按照CPU份额权重(--cpu-shares)分配CPU资源。
2)内存
限制容器实例使用的内存大小,使用的是-m [内存大小]选项。如下:
[[email protected] ~]# docker run -it -m 128M centos:latest bash [[email protected] /]# cat /sys/fs/cgroup/memory/memory.limit_in_bytes 134217728 //128*1024*1024=134217728
3)IO
限制容器实例在设备上的读写速度,使用的是--device-write-bps [设备]:[限速]限制设备上的写速度,以及--device-read-bps [设备]:[限速]限制设备上的读速度。防止某个容器实例吃光这个磁盘的I/O资源。限速的单位可以是kb、mb或gb。
[[email protected] ~]# docker run -it -v /var/www/html:/var/www/html --device /dev/sda:/dev/sda --device-write-bps /dev/sda:1mb centos:latest bash //direct读写数据采用直接IO方式,不走缓存,直接从内存写到硬盘上;nonblock读写数据采用非阻塞IOT方式,优先该命令 [[email protected] /]# time dd if=/dev/sda of=/var/www/html/out bs=1M count=50 oflag=direct,nonblock //可以看到是限制成了1M/s 50+0 records in 50+0 records out 52428800 bytes (52 MB) copied, 50.0133 s, 1.0 MB/s real 0m50.043s user 0m0.000s sys 0m0.161s
(7).扩展:stress压力测试
语法:stress [选项]
参数:
-?, --help 显示帮助文档 --version 显示版本信息 -v, --verbose 显示详细信息 -q, --quiet 静默模式 -n, --dry-run 显示已完成的指令情况 -t, --timeout N 超时时间,默认单位秒 --backoff N 等待N微秒后开始执行 -c, --cpu N 产生N个进程,每个进程反复计算随机数的平方根,测试CPU -i, --io N 产生N个进程,每个进程反复调用sync(),sync()将内存上的内容写入磁盘,测试磁盘 -m, --vm N 产生N个进程,每个进程反复调用内存分配malloc()和内存释放free()函数,测试内存 --vm-bytes B 指定malloc()函数的内存字节数(默认256MB) --vm-stride B 每B个字节创建一个字节(默认4096) --vm-hang N 指定free()函数间隔时间(默认没有,0是下限) --vm-keep 重新启动内存而不是释放和重新分配内存 -d, --hdd N 产生N个进程,每个进程反复调用write()/unlink()函数 --hdd-bytes B 每个硬盘写B字节(默认1GB)
常用参数:-c, --cpu N;-i, --io N;-m, --vm N;--vm-bytes B;--vm-hang N。
(8).扩展:CPU周期控制(了解)
docker提供了--cpu-period(周期)、--cpu-quota两个参数控制容器可以分配到的CPU时钟周期。
--cpu-period是用来指定容器对CPU的使用要在多长时间内重新分配一次。指定周期
--cpu-quota是用来指定在这个周期内,最多可以有多少时间片段用来跑这个容器实例。指定在周期内使用的时间片
与--cpu-shares不同的是,这两个选项分配的是一个绝对值,容器对CPU资源的使用绝对不能超过设定的值。单位为微妙(μ s),--cpu-period最小为1000微秒,最大值为1秒(10^6微秒),默认为0.1秒(100000微秒)。--cpu-quota默认值为-1,表示不做控制。
1秒=1000毫秒,1毫秒=1000微秒。
原文地址:https://www.cnblogs.com/diantong/p/11521726.html