Skip to content

Instantly share code, notes, and snippets.

@jrichardsz
Last active September 13, 2021 17:07
Show Gist options
  • Save jrichardsz/3084d931e0b5b3980e348487e1ee5616 to your computer and use it in GitHub Desktop.
Save jrichardsz/3084d931e0b5b3980e348487e1ee5616 to your computer and use it in GitHub Desktop.
Docker Registry API snippets, dockerregistry, dockerregistryapi

Auth

To get the user & password, execute:

aws ecr get-login --no-include-email --region us-foo-1

That will return

docker login -u AWS -p dwN0wzJXejF== https://123456789.dkr.ecr.us-foo-1.amazonaws.com

Which contains the user, password and docker registry public domain. Set them as basic authentication in your postman or in your curl

search all repositories

curl --location --request GET 'http://192.168.0.20:5000/v2/_catalog' --header 'Authorization: Basic *****'

response will be empty but after some pulls:

{
    "repositories": [
        "ubuntu"
    ]
}

search image tags

request

curl --location --request GET 'https://123456789.dkr.ecr.us-foo-1.amazonaws.com/v2/ubuntu/tags/list' --header 'Authorization: Basic *****'

response

{
    "name": "ubuntu",
    "tags": [
        "1.0.0", "1.0.2", "1.0.3"
    ]
}

user y password are the same used in docker login ... set them as basic authentication in your posmant or in your curl

search all repositories

curl --location --request GET 'http://192.168.0.20:5000/v2/_catalog' --header 'Authorization: Basic *****'

response will be empty but after some pulls:

{
    "repositories": [
        "ubuntu"
    ]
}

search image tags

request

curl --location --request GET 'http://192.168.0.20:5000/v2/ubuntu/tags/list' --header 'Authorization: Basic *****'

response

{
    "name": "ubuntu",
    "tags": [
        "1.0.0"
    ]
}

all public repositories

https://index.docker.io/v1/search?q=ubuntu

get public token

https://docs.docker.com/registry/spec/auth/token/

request

curl "https://auth.docker.io/token?service=registry.docker.io&scope=repository:library/alpine:pull"

response

{
 "token": "eyJhbGci",
 "access_token": "eyJhbGciOiJ",
 "expires_in": 300,
 "issued_at": "2021-09-02T21:02:00.139474473Z"
} 

get latest tag

curl --header "Authorization: Bearer eyJh..." https://index.docker.io/v2/library/alpine/manifests/latest

curl -v https://registry-1.docker.io/v2/_catalog

server

sudo apt install apache2-utils
mkdir auth
htpasswd -Bc auth/.htpasswd my-username
version: "3"
services:
  registry:
      image: registry:2
      ports:
        - 5000:5000
        - 5000:5000
      environment:
        REGISTRY_AUTH: htpasswd
        REGISTRY_AUTH_HTPASSWD_REALM: Registry Realm
        REGISTRY_AUTH_HTPASSWD_PATH: /auth/.htpasswd
        REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY: /data
      restart: unless-stopped
      volumes:
        - ./auth:/auth
docker-compose up -d

client (windows)

search the daemon.json and add

"insecure-registries":["192.168.aa.bbb:5000"]

after that, you will be able to login

docker login 192.168.aa.bbb:5000

source: https://www.cloudsavvyit.com/10259/how-to-create-your-own-private-docker-registry/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment