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
    

      

     

  • 相关阅读:
    MongoDB 集合上限说明
    MongoDB mtools-你可能没用过的mongodb神器(转载)
    Redis 你知道 Redis 的字符串是怎么实现的吗?(转载)
    Mongoimport 导数据自动去重
    MongoDB 数据类型
    MongoDB 数据类型整理
    MongoDB mongoimport 时间格式处理
    MongoDB 空值数组查询
    MongoDB WiredTiger 存储引擎cache_pool设计(转载)
    MongoDB运维实战lsm降低Disk Lantency(转载)
  • 原文地址:https://www.cnblogs.com/BigWrite/p/13280386.html
Copyright © 2011-2022 走看看