美文网首页Docker入门到放弃
Docker(六)DockerRegistry&资源限制

Docker(六)DockerRegistry&资源限制

作者: Starlightskm | 来源:发表于2020-06-27 12:02 被阅读0次

DockerRegistry

DockerRegistry的分类

Registry用于保存docker镜像,包括景象的层次结构和元数据

用户可以自建Registry,也可以使用官方的dockerhub

  • 分类如下:

    • Sponsor Restory:第三方的registry,供客户和docker社区使用

    • Mirror Registry:第三方的registry,只供客户使用

    • Vendor Registry: 由发布Docker镜像的供应商提供的Registry

    • Private Registry:通过舍友防火墙和额外安全层的私有实体提供的Registry

Docker Registry的组成

  • Repostory

    • 由特定的docker镜像的所有迭代版本组成的镜像仓库

    • 一个registry可以存在多个Repostory

      • Registory可以分为顶层仓库用户仓库

      • 用户仓库名称更是为用户名/仓库名

    • 每个仓库可以包含多个Tag,每个Tag只对应一个镜像

  • Index: 维护用户账户,镜像的校验以及公共命名空间信息,相当于为Registry提供了一个拥护认证和检索的接口

镜像的制作 与推送

docker registry中的镜像由开发或者运维人员制作,而后推送到“公共”或者“私有”Repostry上保存,供其他人使用

例如: 部署到生产环境


image.png

Docker私有仓库的搭建

  • 注意事项

    • 生产环境需要构建成高可用形式

    • 使用阿里云镜像仓库,创建私有仓库即可

安装和配置私有仓库

docker-distribution的配置与使用

  • 配置docker-distribution

[root@centos7-node2 ~]# yum -y install docker-distribution

[root@centos7-node2 ~]# vim /etc/docker-distribution/registry/config.yml 

version: 0.1

log:

  fields:

    service: registry

storage:

    cache:

        layerinfo: inmemory

    filesystem:

        rootdirectory: /data/registry

http:

    addr: :5000

[root@centos7-node2 ~]# mkdir /data/registry

[root@centos7-node2 ~]# systemctl restart docker-distribution

  • 打tag与上传镜像

[root@centos7-node1 ~]# vim /etc/docker/daemon.json

{

  "bip": "172.31.0.1/16",

  "registry-mirrors": ["https://0b8hhs68.mirror.aliyuncs.com"],

  "insecure-registries": ["http://192.168.56.12:5000"],

  "storage-driver": "overlay2",

  "graph":"/data/docker",

  "storage-opts": [

    "overlay2.override_kernel_check=true"

  ]

}

[root@centos7-node1 ~]# scp /etc/docker/daemon.json 192.168.56.12:/etc/docker/

[root@centos7-node1 ~]# ssh 192.168.56.12 systemctl restart docker

[root@centos7-node1 ~]# systemctl restart docker

[root@centos7-node1 ~]# docker tag centos:7 192.168.56.12:5000/centos:7   #打标签

[root@centos7-node1 ~]# docker push 192.168.56.12:5000/centos:7              #上传镜像

[root@centos7-node1 ~]# docker tag myimg:v0.6 192.168.56.12:5000/myimg:v0.6

[root@centos7-node1 ~]# docker push 192.168.56.12:5000/myimg:v0.6       #上传镜像

[root@centos7-node2 v2]# docker pull  192.168.56.12:5000/myimg:v0.6

[root@centos7-node2 v2]# docker pull quay.io/coreos/flannel:v0.12.0-amd64    #获取第三方镜像

Harbor

  • 依赖:

    • docker: 17.06+

    • docker-compose: 1.18+

  • 部署与使用 - harbor-offline-installer-v2.0.0

    • 默认证书模式关闭

[root@centos7-node2 ~]# yum -y install epel-release docker docker-compose

[root@centos7-node2 ~]# tar xf harbor-offline-installer-v2.0.0.tgz

[root@centos7-node2 ~]# cd harbor

[root@centos7-node2 harbor]# cp harbor.yml.tmpl harbor.yml

hostname: 192.168.56.12

# http related config

http:

  # port for http, default is 80\. If https enabled, this port will redirect to https port

  port: 80

# https related config

#https:

#  # https port for harbor, default is 443

#  port: 443

#  # The path of cert and key files for nginx

#  certificate: /your/certificate/path

#  private_key: /your/private/key/path

[root@centos7-node2 harbor]# mkdir /data/     #数据目录默认是/data

[root@centos7-node2 harbor]# bash install.sh   #开始安装

  • 登陆harbor: 默认账户和密码是(admin/Harbor12345)

  • 创建账户

  • 创建prod项目,并将创建的账户加入prod项目

  • 在镜像打tag并传到上面创建的prod项目下


[root@centos7-node1 ~]# vim /etc/docker/daemon.json 

{

  "bip": "172.31.0.1/16",

  "registry-mirrors": ["https://0b8hhs68.mirror.aliyuncs.com"],

  "insecure-registries": ["http://192.168.56.12"],

  "storage-driver": "overlay2",

  "graph":"/data/docker",

  "storage-opts": [

    "overlay2.override_kernel_check=true"

  ]

}

[root@centos7-node1 ~]# systemctl restart docker

[root@centos7-node1 ~]# docker tag php-httpd:v0.6 192.168.56.12/prod/php-httpd:v0.6

[root@centos7-node1 ~]# docker login 192.168.56.12     #使用刚创建好的镜像仓库的账户登陆即可

资源限制

  • NameSpace: 资源隔离

  • Cgroups: 资源限制

内存(memory)资源的限制

  • 常见参数
选项 描述
-m or --memory 限制最大空间的内存,要与--memory-swap结合使用
--memory-swap 允许使用交换分区的大小(建议不启用)
--memory-swappiness 使用交换分区的倾向性(建议不启用)
--memory-reservation 给系统预留的内存大小
--kernel-memory 给内核预留的内存大小
--oom-kill-disable 禁止oom而kill容器

CPU资源的限制

  • 常见参数
选项 描述
--cpus=value 指定占用cpu的容量,最大值是宿主机的CPU核心数(1core=1000m[微核])
--cpu-period=value 倾向性指定,1.13之后被废弃
--cpu-quota=value 1.13之后被废弃
--cpuset-cpus 指定跑在哪个宿主机CPU核心上,实现CPU绑定
--cpu-shares 共享CPU,会按照配额动态去占用宿主机cpu资源

docker-stress-ng压测


[root@centos7-node1 ~]# docker pull lorel/docker-stress-ng

[root@centos7-node1 ~]# docker run --name stress -it --rm lorel/docker-stress-ng --help   #查看帮助

[root@centos7-node1 ~]# docker run --name stress --cpus 2 --rm lorel/docker-stress-ng -c 2   #对2核心CPU机器压测

[root@centos7-node1 ~]# docker run --name stress --cpus 2  --cpuset-cpus 0,1 ---rm lorel/docker-stress-ng -c 2   #对2核心CPU机器压测(只压测第0核和第1核心)

[root@centos7-node1 ~]# docker run --name stress -m 512m --rm lorel/docker-stress-ng -vm 2   #  内存压测总共512m的内存,分给两个进程

相关文章

网友评论

    本文标题:Docker(六)DockerRegistry&资源限制

    本文链接:https://www.haomeiwen.com/subject/omvmfktx.html