skip to Main Content

I am trying to setup amazon-ecr-credential-helper on centos 7 machine. Used this document provided by aws as reference : https://github.com/awslabs/amazon-ecr-credential-helper

Can someone please help?

3

Answers


  1. AWS push their version of Centos so they are not interested in making this available. The same RPM might work but the manual install process is easy enough.

    Based on this this blog

    Install Go and git

    yum install -y wget git
    wget https://dl.google.com/go/go1.13.linux-amd64.tar.gz
    tar -C /usr/local -xzf go1.13.linux-amd64.tar.gz
    echo "export PATH=$PATH:/usr/local/go/bin" >> $HOME/.bash_profile
    source ~/.bash_profile
    

    Install the helper and move it into the path

    go get -u github.com/awslabs/amazon-ecr-credential-helper/ecr-login/cli/docker-credential-ecr-login
    cp /root/go/bin/docker-credential-ecr-login /usr/bin
    

    Config, please adjust as needed. Note the region is also in the config.json file

    mkdir ~/.aws/
    cat > ~/.aws/credentials << EOF
    [default]
    region = us-west-1
    aws_access_key_id = xxxxxxx
    aws_secret_access_key = xxxxx
    EOF
    
    mkdir ~/.docker/
    cat > ~/.docker/config.json << EOF
    {
        "credHelpers": {
            "xxxxx.dkr.ecr.us-west-1.amazonaws.com": "ecr-login"
        }
    }
    EOF
    

    Then your pull should work with

    docker pull xxxx.dkr.ecr.us-west-1.amazonaws.com/arkis_nginx:latest
    
    Login or Signup to reply.
  2. You can clone and build manually.

    First install wget and git:

    yum install -y wget git
    

    Then install go lang:

    wget https://dl.google.com/go/go1.13.linux-amd64.tar.gz
    sudo tar -C /usr/local -xzf go1.13.linux-amd64.tar.gz
    

    Add go lang to path, add following line to end of /etc/profile:

    export PATH=$PATH:/usr/local/go/bin
    

    Then run it to reload path:

    source /etc/profile
    

    Finally clone the aws credentials helper, build it and copy to /usr/local/bin:

    git clone https://github.com/awslabs/amazon-ecr-credential-helper.git
    cd amazon-ecr-credential-helper
    make docker
    sudo cp amazon-ecr-credential-helper/bin/local/docker-credential-ecr-login /usr/local/bin
    
    Login or Signup to reply.
  3. In a comment you mention Jenkins. If that is your use case, note that the Pipeline: AWS Steps plugin provides an ecrLogin() which you could use in a Jenkinsfile as follows, by-passing the need to install the ECR Credential Helper:

    environment {
      credentials = 'my-credentials'
      registry = 'https://123456789012.dkr.ecr.us-west-1.amazonaws.com'
      region = 'us-west-1'
      dockerImage = ''
    }
    
    stage('Create image') {
      steps{
        script {
          dockerImage = docker.build('my-image', '--no-cache .')
        }
      }
    }
    
    stage('Push image to repository') {
      steps {
        script {
          withAWS(credentials: credentials, region: region) {
            sh ecrLogin() 
            docker.withRegistry( registry ) {
              dockerImage.push()
            }
          }
        }
      }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search