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小木屋阅读原文】。感谢您的支持!

您可能感兴趣的

Gradle 4.9 is here: Fixed leaks, experimental new ... Our beloved automation system is back with a fresh update! Gradle 4.9 has been released and it is fully packed with awesome and handy new fe...
Containers and Clusters and Swarms, Oh My! It may sound like hyperbole, but put simply, there is a revolution underfoot: Cloud resources and smarter tools have enabled systems that provide enor...
GitHub API Authentication with Insomnia and OAuth ... OAuth 2.0 has been a supported authentication scheme in Insomnia for some time now but – if you are new to OAuth – can still be quite complicated....
Justifying My Existence In Your API Sales And Mark... I feel like I’m regularly having to advocate for my existence, and the existence of developers who are like me, within the sales and marketing fu...
Unable to load a PDF document into the Web API I am getting error while downloading and opening pdf files as Failed to load PDF document. But when i tried to download txt file it gets down...