0

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 Answer 1

1

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.

4
  • After decoding AWS's response I was trying this: curl --unix-socket /var/run/docker.sock -d '{"username":"AWS","serveraddress":"<server_address>", "password": "<password>"}' -X POST http://localhost/auth But not getting any response. Do you havre any idea about this!! Commented Nov 27, 2018 at 2:28
  • Decoded response is like: AWS:<long_string....>. So my username is AWS and password is <long_string....>. Commented Nov 27, 2018 at 2:30
  • Sorry I misunderstood your original question, by docker API call you mean with a curl instead of the "docker login -u AWS -p <password>' command? Commented Nov 27, 2018 at 3:15
  • Yes, sir. See this: docs.docker.com/engine/api/v1.37/#operation/SystemAuth Commented Nov 27, 2018 at 3:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.