Authenticate ECR via Docker Remote API

531 views Asked by At

I need to login to my AWS ECR repository so it can pull whatever images it needs by using API. I need to translate what aws ecr get-login --no-include-email --registry-ids <registry_id> command does using Docker API.

For example --

  1. [Solved] API call needs to be made to AWS in order to get login credentials for docker
    • API call for this will give me base64encoded string which has username and password
  2. How to use those AWS creds in a docker login API (by using Docker Remote API) call (equivalent to docker login -u AWS -p <password> <server_address>)??
1

There are 1 answers

4
Victor Wong On

This is what I do -

  1. Get the output from AWS API
  2. Process the AWS API output to get the base64encoded string
  3. Run docker login API call with the base64encoded string

If you have access to bash -

#!/bin/bash

login_command=$(aws ecr get-login | sed 's/-e none//g' | sed 's/  */ /g')

if (echo "$login_command" | grep -q -E '^docker login -u AWS -p')
then
  $login_command;
fi

You could translate the logic into other languages as you wish.