使用三种方式实现从docker hub 下载镜像,并推送到私有仓库
Docke client
- docker pull nginx
- docker tag nginx opshar.xxxx.com/app/nginx
- docker login opshar.xxxx.com
- 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
原文地址:https://blog.51cto.com/aegis8/2417026