Docker Remote API 开发(一)

存储架构 2016-10-20

基本常见的Docker Control Panel 都是收费的,所以手贱打算自己弄一个玩,技术栈:

预期效果图:

因为我机器是使用Docker Machine创建,所以默认已经从Unix socket转发到了tcp port,如果是自己配置,需要在node节点上修改配置文件:

root@node-1:~# cat /etc/default/docker

DOCKER_OPTS='
-H tcp://0.0.0.0:2376
-H unix:///var/run/docker.sock
--storage-driver aufs
--tlsverify
--tlscacert /etc/docker/ca.pem
--tlscert /etc/docker/server.pem
--tlskey /etc/docker/server-key.pem
--label provider=aliyunecs

'

这里注意一下-H 就是转发的配置了,另外还有tls的验证选项,详细配置请看文档:

使用Docker Remote API v1.24,调用远程接口测试:

curl -v -k -E https://{SERVER_IP}:2376/images/json 
  --cert ~/.docker/machine/machines/hz-1/cert.pem 
  --key ~/.docker/machine/machines/hz-1/key.pem 
  --cacert ~/.docker/machine/machines/hz-1/ca.pem

可以拿到数据:

[
    {
        "Id":"sha256:6ff756f6fc44903216bf36e941db37ed5bb707c533c9c07e513d02fc7dfad4ad",
        "ParentId":"",
        "RepoTags":[
            "redis:3.2.3-alpine"
        ],
        "RepoDigests":[
            "redis@sha256:fe846dd3decd53475c7f6b007ccf10834bdd60d3a649ebdb69f43aa10393e80f"
        ],
        "Created":1474338745,
        "Size":20379436,
        "VirtualSize":20379436,
        "Labels":{

        }
    }
]

待续。

---------分割线---------

curl问题:

OS X: Using PEM private keys fail with error: OSStatus -25299

找到解决方法:

For anyone else getting to this issue when searching for "OSStatus -25299", this is how to convert a pem + cert to pkcs12..

openssl pkcs12 -export -in ./client.crt -inkey ./client.pem -out client.p12

where client.crt is your cert, client.pem is your private key, and client.p12 is your new password encrypted cert/key pkcs12 container.

With that I was able to use curl correctly with something like:
curl -v -k -E ./client.p12:password http://url

更简单的:

or just install curl with openssl support:

$ brew install curl --with-openssl
$ brew link curl --force
$ brew --version
curl 7.50.1 (x86_64-apple-darwin15.6.0) libcurl/7.50.1 OpenSSL/1.0.2h zlib/1.2.5
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: IPv6 Largefile NTLM NTLM_WB SSL libz TLS-SRP UnixSockets
(Note: You will probably need to run brew uninstall curl if you have another version of cURL installed using Brew.)

原贴地址:

OS X: Using PEM private keys fail with error: OSStatus -25299 · Issue #283 · curl/curl · GitHub

苏依蜀黍de小木屋

责编内容by:苏依蜀黍de小木屋 (源链)。感谢您的支持!

您可能感兴趣的

Docker – the Solution for Isolated Environments Docker is a virtualization platform based on containers, which unlike, the ...
Smaller Oracle Docker images One of the important challenges with Docker is to get used to the image layers ...
Eloquent ORM —— API 资源类:架起模型与 JSON API 之间的桥梁... 简介 构建API 时,在Eloquent 模型和最终返回给应用用户的JSON 响应之间可能需要一个转化层。Laravel 的资源类允许你以简单优...
0 to serverless in 60 seconds – OpenFaaS #fa... OpenFaaS or Functions as a Service is a Cloud Native framework for bu...
10 Popular API Testing Interview Questions API testing has been considered an indispensable part of the software testing in...