码迷,mamicode.com
首页 > Windows程序 > 详细

docker remote api

时间:2019-07-04 15:58:54      阅读:163      评论:0      收藏:0      [点我收藏+]

标签: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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!