【问题标题】:Push Docker Repository to Dockerhub with Jenkins使用 Jenkins 将 Docker 存储库推送到 Dockerhub
【发布时间】:2016-01-14 17:02:30
【问题描述】:

我们想将一个 docker 存储库推送到 DockerHub - 从 shell 是可行的。但在 Jenkins 中,我们收到错误消息 "errorDetail":{"message":"unauthorized: access to the requested resource is not authorized"

我认为问题在于在 shell(docker login)中我必须插入电子邮件地址、登录名和密码。在詹金斯我只能设置登录名和密码没有电子邮件。 凭据插件的版本是 1.24,我们使用 docker-build-step 作为 docker 步骤。

谢谢

【问题讨论】:

    标签: plugins jenkins docker dockerhub


    【解决方案1】:

    你可以试试CloudBees Docker Build and Publish plugin吗?

    此插件允许创建构建步骤来构建 Dockerfile 并将映像发布到注册表(DockerHub 或私有注册表):

    另一种解决方案是使用 jenkins 用户在您的 Jenkins 机器上打开一个会话 + 使用相关凭据登录 DockerHub?

    使用此解决方案,DockerHub 凭据将被缓存,并且 Jenkins 应该能够将您的图像推送到 DockerHub 注册表。

    【讨论】:

    • 嗨,在 CloudBees Docker Build and Publish 插件中,我们遇到了同样的问题。如果您想添加一些凭据,我们使用“添加”按钮,在这里您只能插入用户名和密码。除了cloudbees.com/blog/… 之外没有邮箱输入框...
    • 您是否尝试过第二种解决方案? (使用命令行和相关的 jenkins 用户打开 Docker 会话)
    • 我们的 docker 在第二个容器中运行,我们有 testet 登录并推送到 shell。 docker 守护进程在 root 下运行,并将信息保存在“保存在 /root/.docker/config.json 中的登录凭据”中 - 但我们得到了同样的错误。
    • 你运行的是什么版本的 docker?
    • 你使用 Jenkins Swarm 插件吗?我有一个 Jenkins Swarm Slave Container 来完成这种任务,并且为您提供最低的设置成本。 Dockerhub:blacklabelops/swarm-dockerhost
    【解决方案2】:

    也许你可以使用Docker pipeline plugin(它包含在推荐的插件中)。

    Jenkins文件示例:

    node {
    
      checkout scm
      def dockerImage
    
      stage('Build image') {
        dockerImage = docker.build("username/repository:tag")
      }
    
      stage('Push image') {
        dockerImage.push()
      }   
    
    }
    

    这样做,您必须在管道模型定义中指定 docker 注册表的凭据。

    Docker 管道插件在将管道模型定义中分配的凭据应用于具有多分支管道的项目时出现问题。也就是说,如果使用上面的代码你继续收到错误:

    拒绝:请求的资源访问被拒绝

    然后您必须在 Jenkinsfile 中指定凭据,如下所示:

    node {
    
      checkout scm
      def dockerImage
    
      stage('Build image') {
        dockerImage = docker.build("username/repository:tag")
      }
    
      stage('Push image') {
        docker.withRegistry('https://registry-1.docker.io/v2/', 'docker-hub-credentials') {
          dockerImage.push()
        }
      }
    
    }
    

    如果需要,您可以将 URL 修改为自定义注册表

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多