zoukankan      html  css  js  c++  java
  • 【Docker】第四篇 Docker仓库管理

    一、仓库概述

    • 仓库(Repository)Docker仓库主要用于镜像的存储,它是镜像分发、部署的关键。仓库分为公共仓库和私有仓库。
    • 注册服务器(Registry)和仓库区别注册服务器上往往存放着多个仓库,每个仓库中又包含了多个镜像,每个镜像有不同的标签(tag)
    • 官方的公用仓库Docker Hub:如果仅仅是搜索和使用Docker Hub的公共镜像,不需要Docker Hub账户就可以直接操作。如果要上传和分享我们自己创建的镜像,就需要Docker Hub账户。注:注册账户需要借助FQ工具

    二、仓库管理

    1、注册账号
    https://hub.docker.com/ #在此页面注册账号,需要用户名,邮箱,密码(注:需要FQ才能注册,注册通过邮箱激活后可以通过网页登陆)
    2、登陆docker hub
    root@localhost ~]# docker login
    #Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
    Username: *******      
    Password: 
    Login Succeeded
    3、查找镜像   #可参考https://www.cnblogs.com/yangleitao/p/9683104.html
    [root@localhost ~]# docker search centos #可以加上版本号
    4、下载镜像
    [root@localhost ~]# docker pull centos
    5、上传镜像
    #我们可以把自己的镜像传到docker hub官网上,前提是已经注册了账号
    [root@localhost ~]# docker push image_name   

    三、搭建私有仓库

    1、使用registry镜像创建私有仓库
    [root@localhost ~]# docker search registry
    NAME                                    DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
    registry                                The Docker Registry 2.0 implementation for s…   2216                [OK]                
    [root@localhost ~]# docker pull registry   #直接下载镜像
    [root@localhost ~]# docker images    #查看新下载的镜像
    
    2、
    [root@localhost ~]# mkdir -p /data/registry/   #创建一个本地目录,等一下挂载
    [root@localhost ~]# 
    [root@localhost ~]# docker run -d -p 5000:5000 -v /data/registry/:/tmp/registry registry
    599c0e1a298f5e7a19b9ba01ff314c3e3a26a22b3cba1e6800e21ffb54c8e9d5
    [root@localhost ~]# docker ps
    CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
    599c0e1a298f        registry            "/entrypoint.sh /etc…"   9 seconds ago       Up 7 seconds        0.0.0.0:5000->5000/tcp   vibrant_engelbart
    17c54a92a4e8        ubuntu:latest       "/bin/bash"              6 days ago          Up 6 days                                    quizzical_bhabha
    [root@localhost ~]#

    -d : 后台运行

    -p : 宿主机跟容器映射端口 SERVER_PORT:CONTAINER_PORT

    -v : 挂载宿主机目录到容器中作为数据卷, docker registry上传镜像默认存放到容器/var/lib/registry,将本地/data/registry目录挂载到容器中,避免删除容器是数据丢失

    3、管理私有仓库
    [root@localhost ~]# docker run -d -p 5000:5000 registry 
    19003703c71307603cdb48fab242c96dc34c0e37f0dcfe2e568658abbea40557
    [root@localhost ~]# ps -aux|grep docker
    
    [root@localhost ~]# docker push 192.168.19.130:5000/test
    报如下错: 
    The push refers to a repository [192.168.19.130:5000/test] 
    Get https://192.168.19.130:5000/v1/_ping: dial tcp 192.168.19.130:5000: getsockopt: connection refused 
    解决办法: 
    a,执行 
        echo '{ "insecure-registries":["192.168.19.130:5000"] }' >> /etc/docker/daemon.json   #或者直接修改配置文件
    b, 重启docker client的docker 服务 
    
    [root@localhost ~]# systemctl restart docker  #如果容器没有开启也会报错
    [root@localhost ~]# docker push 192.168.19.130:5000/test1   #再次上传成功
    The push refers to repository [192.168.19.130:5000/test1]
    8d7ea83e3c62: Pushed 
    6a061ee02432: Pushed 
    f73b2816c52a: Pushed 
    6267b420796f: Pushed 
    a30b835850bf: Pushed 
    latest: digest: sha256:a819482773d99bbbb570626b6101fa37cd93a678581ee564e89feae903c95f20 size: 1357
    
    [root@localhost ~]# curl -XGET http://192.168.19.130:5000/v2/_catalog 
    {"repositories":["test","test1"]}
    
    [root@localhost ~]# curl -XGET http://192.168.19.130:5000/v2/test1/tags/list
    {"name":"test1","tags":["latest"]}
    [root@localhost ~]# 
  • 相关阅读:
    NFC性价比高频读卡器首选方案:FM17550
    关于ESP8266和ESP8285的对比
    有没有比NRF51822更好的智能穿戴蓝牙方案
    zigbee CC2530首选方案模组:TZU06A1
    PAN3501兼容AS3933-BTST
    NRF51822和NRF52832的主要区别
    集成模拟温度传感器低成本2.4G CC2500RGPR 中文手册
    USB2.0主机控制器 UPD720114 简单详解
    存储器HK1225-7EQ 使用说明书资料
    爬虫 + 数据
  • 原文地址:https://www.cnblogs.com/yangleitao/p/9715790.html
Copyright © 2011-2022 走看看