写点什么

极客时间运维进阶训练营第二周作业

作者:chenmin
  • 2022-10-30
    新疆
  • 本文字数:1576 字

    阅读完需:约 5 分钟

1.基于 dockerfile,实现分层构建的 nginx 业务镜像

#1.创建工作目录chen@chen:~$ mkdir nginx-centoschen@chen:~$ cd nginx-centos
#2.准备文件chen@chen:~/nginx-centos$ ls -l-rw-rw-r-- 1 chen chen 1229 Oct 30 10:55 CentOS-Base.repo-rw-r--r-- 1 chen chen 38751 Oct 30 09:35 frontend.tar.gz-rw-r--r-- 1 chen chen 1064925 Oct 30 09:33 nginx-1.21.1.tar.gz-rw-r--r-- 1 chen chen 2812 Oct 30 09:34 nginx.conf
#3.编辑Dockerfilechen@chen:~/nginx-centos$ vi DockerfileFROM centos:centos7.9.2009MAINTAINER "chen 370460269@qq.com"RUN yum install -y gcc make zlib zlib-devel pcre pcre-devel expect openssl-develADD nginx-1.21.1.tar.gz /usr/local/src/RUN cd /usr/local/src/nginx-1.21.1 && ./configure --prefix=/apps/nginx && make && make install && ln -sv /apps/nginx/sbin/nginx /usr/binRUN groupadd -g 2088 nginx && useradd -g nginx -s /usr/sbin/nologin -u 2088 nginx && chown -R nginx.nginx /apps/nginxADD nginx.conf /apps/nginx/conf/ADD frontend.tar.gz /apps/nginx/html/EXPOSE 80 443#ENTRYPOINT ["nginx"]CMD ["/apps/nginx/sbin/nginx","-g","daemon off;"]
#4.运行容器镜像chen@chen:~/nginx-centos$ sudo docker run -d -p 80:80 nginx-centos:v11c8297128bf15b3a57475276d7ad438fbd96bc4b97cd007808fed97ce3ea241fchen@chen:~/nginx-centos$ sudo docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES1c8297128bf1 nginx-centos:v1 "/apps/nginx/sbin/ng…" 6 seconds ago Up 5 seconds 0.0.0.0:80->80/tcp, :::80->80/tcp, 443/tcp stupefied_thompson
复制代码

2.基于 docker 实现对容器的 CPU 和内存的资源限制

#1.限制容器CPU使用chen@chen:~/nginx-centos$ sudo docker run -d --rm --name cputest --cpus 1 nginx5cc912243d0af79786fec5eb76bc32867bd7d6152e8c643969108962d2acff3fchen@chen:~/nginx-centos$ sudo docker statsCONTAINER ID   NAME                 CPU %     MEM USAGE / LIMIT    MEM %     NET I/O         BLOCK I/O     PIDS5cc912243d0a   cputest              0.00%     3.246MiB / 3.84GiB   0.08%     656B / 0B       0B / 16.4kB   31c8297128bf1   stupefied_thompson   0.00%     1.863MiB / 3.84GiB   0.05%     3.52kB / 946B   0B / 0B       2
#2.限制容器内存使用chen@chen:~/nginx-centos$ sudo docker run -d --rm -m 256m --name memtest nginxWARNING: Your kernel does not support swap limit capabilities or the cgroup is not mounted. Memory limited without swap.d5d6e0b0fffa453d4e84d2660147019ce5eb7c5253f4f15d32b28f9cae11949bchen@chen:~/nginx-centos$ sudo docker statsCONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDSd5d6e0b0fffa memtest 0.00% 3.191MiB / 256MiB 1.25% 586B / 0B 0B / 16.4kB 31c8297128bf1 stupefied_thompson 0.00% 1.863MiB / 3.84GiB 0.05% 3.45kB / 946B 0B / 0B 2CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
复制代码

3.部署 http 协议的 harbor 镜像仓库

abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd

abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd

abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd


用户头像

chenmin

关注

还未添加个人签名 2018-02-26 加入

还未添加个人简介

评论

发布
暂无评论
极客时间运维进阶训练营第二周作业_chenmin_InfoQ写作社区