最近需要学习docker的Cgroups机制,需要用到stress进行测试,前期工作就是自己创建一个stress镜像。
- 新建一个 Dockerfile 文件
[vagrant@localhost ~]$ mkdir -p /tmp/stress
[vagrant@localhost stress]$ sudo vi Dockerfile
FROM library/centosADD epel-7.repo /etc/yum.repos.d/
RUN yum clean all && yum makecache
RUN yum install -y stress
#CMD与ENTRYPOINT的区别在于执行docker run时参数传递的方式不同
ENTRYPOINT ["stress", "--verbose"] - 构建镜像
[vagrant@localhost stress]$ docker build -t centos-stress:1.0.1 .
- 查看镜像是否生成
[vagrant@localhost stress]$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos-stress 1.0.1 3dd149b42c38 25 minutes ago 713MB - 测试改镜像成功
[vagrant@localhost cgroup]$ docker run -ti --rm -m 200M --memory-swap=300M centos-stress:1.0.1 --vm 1 --vm-bytes 280M
stress: info: [1] dispatching hogs: 0 cpu, 0 io, 1 vm, 0 hdd
stress: dbug: [1] using backoff sleep of 3000us
stress: dbug: [1] --> hogvm worker 1 [5] forked
stress: dbug: [5] allocating 293601280 bytes ...
stress: dbug: [5] touching bytes in strides of 4096 bytes ...
stress: dbug: [5] freed 293601280 bytes
stress: dbug: [5] allocating 293601280 bytes ...
stress: dbug: [5] touching bytes in strides of 4096 bytes ...