๐ŸŒˆ ํ„ฐ๋ฏธ๋„์—์„œ DockerHub ๊ณต๊ฐœ ์ด๋ฏธ์ง€๋ฅผ ๋ณด์—ฌ์ฃผ์„ธ์š”.

5047 ๋‹จ์–ด dockerjsonbeginnersapi

โ” ์†Œ๊ฐœ



Docker Registry HTTP API V2 make๋Š” ํŽธ์•ˆํ•œ ๋ฐฉ๋ฒ•์œผ๋กœ ๋ ˆ์ง€์ŠคํŠธ๋ฆฌ๋ฅผ ์ฟผ๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๊ณต๊ฐœ ์ด๋ฏธ์ง€๋ฅผ ๋ณด์—ฌ์ฃผ๊ธฐ ์œ„ํ•ด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํ•  ์ˆ˜ ์žˆ๋Š”์ง€ ๊ถ๊ธˆํ•ฉ๋‹ˆ๋‹ค.

  • API์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ธฐ
  • jq ์˜ต์…˜์œผ๋กœ ์žฌ์ƒ

  • ํ„ฐ๋ฏธ๋„ ์ž์ฒด์—์„œ ์žฌ๋ฏธ์žˆ๊ณ  ํฅ๋ฏธ๋กœ์šด ๋ฐฉ์‹์œผ๋กœ ์ผ๋ถ€ ์ฝ˜ํ…์ธ  ํ‘œ์‹œ
  • ์ด ์ฃผ์ œ์™€ ๊ด€๋ จํ•˜์—ฌ ๋‹ค๋ฅธ ์ข…๋ฅ˜์˜ ์ฐฝ์˜์ ์ธ ์•„์ด๋””์–ด ์ƒ์„ฑ

  • ๐Ÿ’ก ์•„์ด๋””์–ด



    ์ด๋ฏธ์ง€๋ฅผ ๊ตฌ์ถ•ํ•˜๋Š” ํŒ€์—๊ฒŒ ์ด๋ฏธ์ง€์˜ ์ธ๊ธฐ๋ฅผ ์ž…์ฆํ•˜๊ธฐ ์œ„ํ•ด

    I wanted to display a ranking they could play with on their workstations... right into their terminal



    ๐Ÿงฐ ํˆด๋ง



    ๋”ฐ๋ผ์„œ ํŒ€์—์„œ API๋ฅผ ํ…Œ์ŠคํŠธํ•˜๊ณ  ๋ฌธ์„œํ™”ํ•˜๊ธฐ ์œ„ํ•ด ์ด๋ฏธ ๋งค์ผ ์‚ฌ์šฉํ•˜๋Š” ๋„๊ตฌ๋ฅผ ์‚ฌ์šฉํ–ˆ์Šต๋‹ˆ๋‹ค.

  • httpie : "/aitch-tee-tee-pie/pie๋งŒํผ ์‰ฝ์Šต๋‹ˆ๋‹ค. API ์‹œ๋Œ€๋ฅผ ์œ„ํ•œ ํ˜„๋Œ€์ ์ด๊ณ  ์‚ฌ์šฉ์ž ์นœํ™”์ ์ธ ๋ช…๋ น์ค„ HTTP ํด๋ผ์ด์–ธํŠธ์ž…๋‹ˆ๋‹ค. JSON ์ง€์›, ์ƒ‰์ƒ, ์„ธ์…˜, ๋‹ค์šด๋กœ๋“œ, ํ”Œ๋Ÿฌ๊ทธ์ธ ๋“ฑ. "

  • jq : "jq๋Š” JSON ๋ฐ์ดํ„ฐ์˜ ๊ฒฝ์šฐ sed์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค."

  • ... ๊ทธ๋ฆฌ๊ณ  ์žฌ๋ฏธ์™€ ๊ดด์งœ ๋ฌธํ™”๋ฅผ ์œ„ํ•ด :

  • lolcat : "๋ฌด์ง€๊ฐœ์™€ ์œ ๋‹ˆ์ฝ˜!"

  • http https://hub.docker.com/v2/repositories/optnc | \
         jq -r '"Image\tPulls", "-----------------------\t---", ( .results | sort_by(.pull_count) | reverse | .[] | "\(.name)\t\(.pull_count)")' | \
     column -t -s $'\t' | \
     lolcat -a -d 20
    


    ๐Ÿฟ ๋ฐ๋ชจ



    ์ตœ์ข… ๋ฐ๋ชจ๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.



    ๋ฐ”๋กœ ์•„๋ž˜์—์„œ ๋™์˜์ƒ ์†Œ์Šค ์ฝ”๋“œ๋ฅผ ์ฐพ์œผ์‹ญ์‹œ์˜ค(๋‹ค์‹œ ์žฌ์ƒํ•˜๊ฑฐ๋‚˜ ์‚ฌ์šฉ์ž ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Œ).

    # ๐Ÿค“ Let's see at optnc's public images on DockerHub ๐ŸŽ‡
    
    http https://hub.docker.com/v2/repositories/optnc | jq -r '"Image\tStars\tPulls", "-----------------------\t-------\t------", ( .results | sort_by(.pull_count) | reverse | .[] | "\(.name)\t\(.star_count)\t\(.pull_count)")' | column -t -s $'\t'
    
    # ๐ŸŽฌ Now watching the spicy way ๐ŸŒˆ
    
    clear && http https://hub.docker.com/v2/repositories/optnc | \
         jq -r '"Image\tPulls", "-----------------------\t---", ( .results | sort_by(.pull_count) | reverse | .[] | "\(.name)\t\(.pull_count)")' | \
     column -t -s $'\t' | \
     lolcat -a -d 20
    
    # ๐Ÿ™๐Ÿป Hopefully you enjoyed this short demo ๐Ÿ™‹
    


    ๐Ÿ”– ๋ฆฌ์†Œ์Šค


  • Docker HUB API (beta)
  • Docker Registry HTTP API V2
  • Great collection of DockerHub Docker Registry API call Examples

  • ๐Ÿ“œ ์ดˆ์•ˆ



    ์ตœ์ข… ๋ฒ„์ „์„ ๋งŒ๋“œ๋Š” ๋ฐ ๋„์›€์ด ๋œ ์ดˆ์•ˆ ์•„๋ž˜ ๐Ÿ‘‡

    http https://hub.docker.com/v2/repositories/optnc | jq -r '.results|.[] | "\(.name)\t\(.star_count)"'  | column -t -s $'\t'
    


    ๊ทธ๋Ÿฐ ๋‹ค์Œ ์ •๋ ฌ๋œ ๋ฒ„์ „:

    http https://hub.docker.com/v2/repositories/optnc | jq -r '"Image\tStars", "-----------------------\t-------", ( .results|.[] | "\(.name)\t\(.star_count)" )' | column -t -s $'\t'
    


    desc๋ฅผ ๋ณ„๋ณ„๋กœ ์ •๋ ฌ:

    http https://hub.docker.com/v2/repositories/optnc | jq -r '( .results | sort_by(.star_count) | reverse | .[] | "\(.name)\t\(.star_count)")' | column -t -s $'\t'
    


    ๊ทธ๋Ÿฐ ๋‹ค์Œ lolcat ๋ฐฐ๊ด€์œผ๋กœ :

    http https://hub.docker.com/v2/repositories/optnc | jq -r '"Image\tStars\tPulls", "-----------------------\t-------\t------", ( .results | sort_by(.pull_count) | reverse | .[] | "\(.name)\t\(.star_count)\t\(.pull_count)")' | column -t -s $'\t' | lolcat
    

    ์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ