zoukankan      html  css  js  c++  java
  • docker私有仓库搭建和资源限制

    Docker 私有仓库的搭建

         docker 私有仓库默认只支持https协议的访问  不支持http协议 如果需要允许通过http协议访问 必须手动修改配置文件

         docker官方默认提供的仓库  提供软件包docker-distribution 由python开发的web系统

          #   yum install docker-registry
          #   systemctl start docker-distribution

         非dockerhub的Reistry必须明确指定服务器的地址 端口     非顶层的私有仓库还必须给定用户名

         要想把镜像推送的私有仓库 必须先给镜像打上合适的标签 标签错误是无法上传docker 镜像的

    给镜像打标签
    # docker image ls
      REPOSITORY           TAG                 IMAGE ID            
       myweb                v2                  83d7884335ed   
    # docker tag myweb:v2 192.168.30.137:5000/myweb:v2_2
    
    [root@nginx-docker]# docker push 192.168.30.137:5000/myweb
    The push refers to a repository [192.168.30.137:5000/myweb]
    Get https://192.168.30.137:5000/v1/_ping: http: server gave HTTP response to HTTPS client
    
    #允许运行http协议
    [root@nginx-docker docker]# vi /etc/docker/daemon.json
    {
      "insecure-registries":["192.168.30.137:5000"]
    }
    
    #修改daemon.json 拉取私有仓库镜像
    [root myweb]# docker pull 192.168.30.137:5000/myweb:v2_2
    私有仓库的上传和下载

    HARBOR 搭建私有仓库     

          企业级docker私有仓库项目    原生支持镜像的冗余备份  主要由vmware 中国团队成员开发

          支持访问控制  活动监控  主从复制  

          需要借助docker-compose 单机容器编排工具安装HARBOR

         1.安装docker-compose 

            yum install docker-compose

    # yum install docker-compose
    # https://github.com/vmware/harbor
    1.下载harbor源码
    2.# tar xf harbor-offline-installer-v1.5.2.tgz  -C /usr/local/
    3. vi /usr/local/harbor/harbor.cfg
       hostname = myharbor.com  不能写服务器IP 必须写主机名
       后面无法解析地址 造成上传镜像失败
    4.cd /usr/local/harbor
    5. ./install.sh  自动执行安装脚本
    harbor安装
    5.http://192.168.30.139/harbor/sign-in
      项目 》 新建项目(仓库) 》
    6.harbor上传下载镜像的时候需要进行用户认证的 harbor中创建的用户
    
    
    [root@nginx-docker ~]# docker tag myweb:v2 192.168.30.139/dev/myweb:v2_1
    [root@nginx-docker ~]# docker push 192.168.30.139/dev/myweb:v2_1
    The push refers to a repository [192.168.30.139/dev/myweb]
    Get https://192.168.30.139/v1/_ping: dial tcp 192.168.30.139:443: getsockopt: connection refused
    [root@nginx-docker ~]# vi /etc/docker/daemon.json
    [root@nginx-docker ~]# systemctl restart docker
    [root@nginx-docker ~]# docker push 192.168.30.139/dev/myweb:v2_1
    The push refers to a repository [192.168.30.139/dev/myweb]
    86527283a11a: Preparing 
    b87bb670f898: Preparing 
    841051620742: Waiting 
    717b092b8c86: Waiting 
    denied: requested access to the resource is denied
    [root@nginx-docker ~]# docker login 92.168.30.139
    Username: yxh
    Password: 
    Error response from daemon: Get https://92.168.30.139/v1/users/: dial tcp 92.168.30.139:443: i/o timeout
    
    使用docker login不能使用服务器IP地址,必须使用可以被解析的主机名
    vi /etc/hosts
      192.168.30.139  myharbor.com
    
    [root@nginx-docker ~]# docker login myharbor.com
      Username: yxh
      Password: 
      Login Succeeded
    
    [root@nginx-docker ~]# docker tag myweb:v2 myharbor.com/dev/myweb:v2
    [root@nginx-docker ~]# docker push myharbor.com/dev/myweb:v2
    The push refers to a repository [myharbor.com/dev/myweb]
    86527283a11a: Pushed 
    6263c50a557c: Pushed 
    c6ee3d0df60c: Pushed 
    2eb31a989e11: Pushed 
    v2: digest: sha256:41cfd4c47d2f24ca703ef32ff7de9ed166be65adf7c725ff2894cd0b0125ee2a size: 1774
    
    一次性推送整个仓库
     1.先给多个镜像打上标签
      docker tag myweb:v3-1  myharbor.com/dev/myweb:v3-1
      docker tag myweb:v3-2  myharbor.com/dev/myweb:v3-2
      docker tag myweb:v3-3  myharbor.com/dev/myweb:v3-3
     2.上传整个仓库(把三个镜像上传到同一仓库(myweb)中)
      docker push myharbor.com/dev/myweb 
    
    3.下载镜像
    # docker pull myharbor.com/dev/myweb:v2
    Trying to pull repository myharbor.com/dev/myweb ... 
    v2: Pulling from myharbor.com/dev/myweb
    Digest: sha256:41cfd4c47d2f24ca703ef32ff7de9ed166be65adf7c725ff2894cd0b0125ee2a
    Status: Downloaded newer image for myharbor.com/dev/myweb:v2
    
    docker-compose命令
      停止harbor  docker-compose stop
      启动harbor  docker-compose start
    harbor上传和下载镜像

    harbor仓库的使用

      

    docker容器资源限制

          容器技术能够实现主要依赖于内核的两个特性 名称空间和控制组

          默认情况一个容器是没有使用资源的限制,它能耗掉宿主机上的所有资源

          限制容器的cpu和内存这两种资源

          OOM

              如果系统内核探测到当前宿主机已经没有足够内存可分配给系统运行中重要的系统进程,就会抛出一个系统异常并且会强制杀死一些内存耗用比较大的应用进程

              每个进程都有一个OOM_adj参数 代表一旦发生OOM 是否优先被kill的优先级

        容器内存限制

        容器CPU限制

             cpu核心编号是从0开始编号的

             --cpus   限制容器最多使用多少核cpu

      # docker pull lorel/docker-stress-ng    下载docker容器压测镜像

         启动容器后执行 stress help   查看相关使用文档

  • 相关阅读:
    check事件
    JAVA----泛型
    JAVA集合的遍历for循环、Iterator迭代器
    JAVA 集合的定义分类
    JAVA面向对象---方法的重写与重载
    JAVA 面向对象---继承
    JAVA 面向对象
    JAVA ArrayList集合
    JAVA基础测试
    JAVA中 引用数据类型(类)
  • 原文地址:https://www.cnblogs.com/yxh168/p/9424971.html
Copyright © 2011-2022 走看看