docker remote api

2021-05-23 15:28

阅读:594

标签:ORC   三种方式   pytho   docker   ops   pull   ima   decode   docke   

使用三种方式实现从docker hub 下载镜像,并推送到私有仓库

Docke client

  1. docker pull nginx
  2. docker tag nginx opshar.xxxx.com/app/nginx
  3. docker login opshar.xxxx.com
  4. docker push opshar.xxxx.com/app/nginx

python sdk
首先下载pip install docker

#!/usr/bin/python
import sys, json, docker.from.env()

c = docker.from.env()
try:
client.ping()
except dock.errors.APIError:
print("docker connect failed")
sys.exit(1)

#pull
for line in c.api.pull(‘nginx‘, stream=True, decode=True):
print(json.denps(line, indent=4))
#tag
tag = opshar.xxxx.com/app/nginx
try:
c.api.tag(‘nginx‘, tag, ‘latest‘, force=True)
except docker.errors.APIError:
print("tag failed")
sys.exit(1)

auth_config = {
"username": "admin",
"password": "Harbor12345"
}

#push
for line in c.api.push(tag, stream=True, decode=True, auth_config=auth_config):
print(json.denps(line, indent=4))

remote api
#pull
curl -XPOST http://IP:2375/images/create?fromImage=nginx
#TAG
curl -XPOST http://IP:2375/images/hello-world/tag?repo=opshar.xxxx.com/app/nginx

PUSH

XRA=echo ‘{"username": "admin","password": "Harbor12345", "serveraddress": "opshar.xxxx.com"}‘ | base64 --wrap=0

curl -XPOST -H "X-Registry-Auth: $XRA" \
http://IP:2375/images/opshar.xxxx.com/app/nginx

docker remote api

标签:ORC   三种方式   pytho   docker   ops   pull   ima   decode   docke   

原文地址:https://blog.51cto.com/aegis8/2417026


评论


亲,登录后才可以留言!