zoukankan      html  css  js  c++  java
  • docker 处理git 密码认证问题

    需求:

      docker中需要访问git服务,并将第三方提交到服务的文件同步到git中,需要在docker 容器中进行git push等相关操作,所以需要处理用户认证问题。现在docker容器每次重启都需要到 容器中进行git pull,然后输入用户名密码。

      git有两种连接方式ssh 和http 认证。

    • ssh需要用 ssh-keygen 生成公钥和私钥,并将公钥添加到git中。
    • http需要输入密码,
        git config --global credential.helper store 可以只输入第一次,后续不需要再次输入。

    方案一:

      通过ssh key进行认证处理,但是公司git服务器不支持ssh连接,

    #生成key 
    ssh-keygen
    Enter file in which to save the key (/root/.ssh/id_rsa): 输入保存的文件路径和名称
    #找到生成的key  默认是 /用户名/.ssh/id_rsa
    cat id_rsa.pub
    #将公钥文件内容添加到git服务器中
    #将私钥 id_rsa 放在docker中
    #在dockfile中加入ssh-add  使用指定私钥
    ssh-add ~/.ssh/id_rsa
    #git clone 使用 ssh下载
    git clone git@github.com:BigWrite/test.git
    

      

    方案二:

      将打包好的镜像二次加工成新的镜像。

    #运行打包好的镜像,镜像中没有默认安装git 需要自己安装(windows dockerfile  RUN yum -y install git时报错,所以就没在打镜像时安装)
    #1.运行镜像并进去运行容器
    docker run -it 镜像名称:latest /bin/bash
    #2.进入运行中的容器,容器名称用docker ps -a   查看所有容器||docker ps -s 查看运行中的容器
    docker exec  -it 容器名称 /bin/sh
    #安装git
    yum install git
    #####yum 报域名找不到 "Could not resolve host: mirrors.XXX.tc; Name or service not known"
    #下载阿里yum镜像  http://mirrors.aliyun.com/repo/Centos-7.repo 复制到/etc/yum.repos.d 文件夹下面 命名为CentOs-ali.repo
    vi /etc/yum.repos.d/CentOs-ali.repo
    #再次安装git  不提示yes no
    yum -y install git
    #安装完成后,配置git信息
    git config --global user.name "docker_webgit"
    git config --global user.email "bigwrite@163.com"
    git config --global credential.helper store
    git config --global push.default "current"
    #执行 git clone  输入用户名和密码
    git clone XXX.git
    #退出当前容器
    exit
    #用配置好的容器,再次打包 容器id可以用 docker ps -a查看
    docker commit 容器ID 新镜像名称
    #查看打包好的镜像 然后push到服务集群就ok了
    docker images
    

      

     

  • 相关阅读:
    CodeForces Virtual Participation 记录
    Raney 引理学习笔记
    题解 CF1503A Balance the Bits
    CF1493D GCD of an Array 题解
    原根表
    LOJ6102「2017 山东二轮集训 Day1」第三题 or 51nod1355 斐波那契的最小公倍数 题解
    解决js动态改变html元素而html内容只在初末时改变的问题
    【命题逻辑实验题】求给定命题公式的真值表[C语言程序实现](支持蕴含式的运算)
    【C语言】模拟简单的《掘地求生Getting Over It》(源码)
    【C语言】英雄联盟英雄查询系统(源码)
  • 原文地址:https://www.cnblogs.com/BigWrite/p/13280386.html
Copyright © 2011-2022 走看看