Welcome to the Linux Foundation Forum!

Chap 9 - dockerlogin credentials in Jenkins do not work with Docker hub access tokens?

Hello,

I have heard in the lesson of chapter 9 that we should configure Jenkins credential to access docker hub using our own password of the docker hub

As I am a stubborn person, I struggled to do some test to make the access token work in Jenkins, taking into account that it works perfectly fine with "docker login" command under /bin/bash

But indeed the access token does not seem to work in Jenkins! would someone have a clue on that? I also hardly find some documentation about index.docker.io, and it seems related to that (cannot neither use "docker image push" explicitely on index.docker.io

Thank you for your help
Laurent

Answers

  • @laurent.roffe I principally like the idea of using access tokens instead of a password. However, I have not given this a try yet (using access token and adding it as a cred on jenkins). I will set this up, try using access token and report.

  • Thanks Gourav !

  • @laurent.roffe I got a chance to test this today and happy to report that access token from docker hub works fine as a replacement to the password. No issues at all.

    Following is the code that I have tried this with,

          stage('Docker BnP'){
              agent any
              steps{
                echo 'Packaging vote app with docker'
                script{
                  docker.withRegistry('https://index.docker.io/v1/', 'dockerlogin') {
                      def voteImage = docker.build("xxxxxx/vote:v${env.BUILD_ID}", "./vote")
                      voteImage.push()
                      voteImage.push("dev")
                  voteImage.push("latest")
                  }
                }
              }
          }
    
    
    

    where registry is defined as https://index.docker.io/v1/ and reference to docker creds as dockerlogin. Adding username + access token with id=dockerlogin on Jenkins in addition to this works for me.

    If you get a specific error, would be helpful if you could share the details of it.

  • Thanks Gourav for your feedback. I will test again, knowing that I saw later that jenkins creates the docker hub repositories on the fly, with private visibility, and that I have no credit for that. I guess the error was not related to passwords but to private repositories. I'll come back to you when done

Categories

Upcoming Training