基于centos 创建一个stress镜像

最近需要学习docker的Cgroups机制,需要用到stress进行测试,前期工作就是自己创建一个stress镜像。

  1. 新建一个 Dockerfile 文件
    [vagrant@localhost ~]$ mkdir -p /tmp/stress
    [vagrant@localhost stress]$ sudo vi Dockerfile
    FROM library/centos
    
    ADD 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"]

       

  2. 构建镜像
    [vagrant@localhost stress]$ docker build -t centos-stress:1.0.1 .

     

  3.  查看镜像是否生成
    [vagrant@localhost stress]$ docker images          
    REPOSITORY                                       TAG                 IMAGE ID            CREATED             SIZE
    centos-stress                                    1.0.1               3dd149b42c38        25 minutes ago      713MB

      

  4. 测试改镜像成功
    [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 ...

     

 

  

posted @ 2018-02-26 14:09  我为什么要写这个  阅读(243)  评论(0编辑  收藏  举报