docker remote api

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了docker remote api相关的知识,希望对你有一定的参考价值。

使用三种方式实现从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的主要内容,如果未能解决你的问题,请参考以下文章

sh ?为docker-machine中的所有机器调用Docker Remote API

sh ?为docker-machine中的所有机器调用Docker Remote API

docker remote api

Docker开启Remote API 访问 2375端口

docker 开启remote api

docker remote api 的安全隐患