美文网首页
dockerfile 访问私有仓库

dockerfile 访问私有仓库

作者: 孙小兵 | 来源:发表于2022-01-22 18:45 被阅读0次

在go项目中通过docker file 来构建镜像,使用镜像来进行后续的工作,是非常高效且常用的工作模式。但如果项目中引入私有仓库,这时通过docker file 文件构建时,会遇见一下几个问题:

1. 私有仓是http协议的问题

//需要在docker file 文件中 新增 命令
ENV GOINSECURE=".myname.com,.gitlab.com,*.gitee.com"
//使用http 协议拉取代码

2. 私有仓拉去代码的账号 密码问题

  • 方案一:
    在原始的镜像基础上,构建自己的镜像(已保存git 相关账号 密码),业务中docker file 以自己镜像为基础,再开构建。
    docker run -it golang:1.16 /bin/sh
    //to do
    git config --global credential.helper store
    git config --global user.email "你的邮箱"
    git config --global user.name "你的github用户名"
    // 构建自己的镜像
    docker commit CONTAINER 新镜像[:TAG]

  • 方案二
    首先在git 中配置SSH 等配置
    拷贝密钥,设置私有库拉取
    ADD ./.ssh/ /root/.ssh
    //配置自己项目地址 (git 代替http)
    RUN git config --global url."git@gitlab.com:".insteadOf "http://git.gitlab.com/"
    RUN go mod tidy

相关文章

网友评论

      本文标题:dockerfile 访问私有仓库

      本文链接:https://www.haomeiwen.com/subject/gctphrtx.html