码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • 自动拉取和推送docker镜像到私有仓库(skopeo)


    1、相关资源导航
    https://blog.csdn.net/zyj81092211/article/details/123068347

    2、环境介绍
    操作系统:Centos 7.9
    docker版本:20.10.17
    私有仓库:harbor
    工具:shell、skopeo

    3、安装skopeo
    (1)下载源码包
    https://github.com/containers/skopeo/releases
    在这里插入图片描述

    wget https://github.com/containers/skopeo/archive/refs/tags/v1.9.2.tar.gz
    tar -xvf v1.9.2.tar.gz
    
    • 1
    • 2

    (2)安装go-md2man并获取程序目录
    https://centos.pkgs.org/7/epel-aarch64/golang-github-cpuguy83-go-md2man-1.0.4-5.el7.aarch64.rpm.html
    在这里插入图片描述

    rpm -ivh https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/g/golang-github-cpuguy83-go-md2man-1.0.4-5.el7.x86_64.rpm
    whereis go-md2man 
    
    • 1
    • 2

    在这里插入图片描述
    (3)进入skopeo目录,进行容器编译

    docker run -v  $PWD:/src -v /usr/bin/go-md2man:/go/bin/go-md2man -w /src -e CGO_ENABLED=0 golang make BUILDTAGS=containers_image_openpgp GO_DYN_FLAGS=
    
    • 1

    在这里插入图片描述
    (4)运行skopeo执行文件

    bin/skopeo -v
    
    • 1

    在这里插入图片描述
    (5)移动软件目录到/usr/local下,并创建bin文件软连接

    mv skopeo-1.9.2/ /usr/local/skopeo
    ln -s /usr/local/skopeo/bin/skopeo /usr/local/bin/skopeo
    
    • 1
    • 2

    )
    (6)编译后的bin文件分享
    编译未成功的可以试试这个
    https://download.csdn.net/download/zyj81092211/86501240

    4、skopeo命令
    在这里插入图片描述

    skopeo login --tls-verify=false -u xxx -p xxx harbor.wtown.com
    
    • 1

    在这里插入图片描述
    推送一个镜像

    skopeo copy --insecure-policy --src-tls-verify=false --dest-tls-verify=false docker://docker.io/mysql:8.0.30-oracle docker://harbor.wtown.com/wtown/mysql:8.0.30-oracle
    
    • 1

    在这里插入图片描述
    仓库中已有
    在这里插入图片描述
    5、创建同步脚本

    vi /usr/local/bin/autoimagesync
    
    • 1

    添加如下(更换私有仓库信息)

    set -e
    
    input_info=$1
    source_image_name=`echo $input_info | awk -F ':' '{ print $1  }'`
    destination_image_name=`echo $input_info | awk -F ':' '{ print $1  }'  | awk  -F '/' '{ print $NF  }'`
    image_tag=`echo $input_info | awk -F ':' '{ print $2  }'`
    
    if [ ! -n "$image_tag" ]; then
       echo "未输入TAG,使用默认latest"
       image_tag=latest
    else
       echo 'TAG是$image_tag'
    fi
    
    #定义私有仓库信息
    harbor_registry='harbor.wtown.com'
    project='wtown'
    user='xxx'
    password='xxx'
    
    echo "登陆私有仓库..."
    skopeo login --tls-verify=false -u ${user} -p ${password} ${harbor_registry}
    if [[ $? -eq 0 ]] ;then
            echo "登陆成功成功!!!"
    fi
    
    echo "开始同步镜像..."
    skopeo copy --insecure-policy --src-tls-verify=false --dest-tls-verify=false docker://docker.io/${source_image_name}:${image_tag} docker://${harbor_registry}/${project}/${destination_image_name}:${image_tag}
    if [[ $? -eq 0 ]] ;then
            echo "镜像同步成功!!!"
    fi
    
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33

    添加执行权限

    chmod +x /usr/local/bin/autoimagesync
    
    • 1

    测试如下
    在这里插入图片描述

  • 相关阅读:
    碳量子点CQDs,溶于DMSO(二甲基亚砜) ,发射波长440nm,630nm
    从技术走向管理
    C51--单片机中断
    爱奇艺、优酷、腾讯视频 限制设备登录 唯一登录设计原理
    基于AERMOD模型在大气环境影响评价中的实践
    VTK - Boolean布尔操作
    数据结构——栈和队列
    基于数字孪生的城市地下智慧管网
    c/c++常见的数据类型表示的范围
    [网鼎杯 2020 朱雀组]phpweb call_user_func()
  • 原文地址:https://blog.csdn.net/zyj81092211/article/details/126555530
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号