docker stats详解1.6.2 的 Client API 不支持stats了吗

docker连接不了的有关问题 - 移动开发当前位置:& &&&docker连接不了的有关问题docker连接不了的有关问题&&网友分享于:&&浏览:0次docker连接不了的问题
docker连接不了的问题
FATA[0000] Get http:///var/run/docker.sock/v1.17/info: dial&
unix /var/run/docker.sock: no such file or directory.&
Are you trying to connect to a TLS-enabled daemon without TLS?
boot2docker start
export DOCKER_HOST=tcp://192.168.59.103:2376
export DOCKER_CERT_PATH=/Users/wuxueying/.boot2docker/certs/boot2docker-vm
export DOCKER_TLS_VERIFY=1
? ~ docker version
Client version: 1.5.0
Client API version: 1.17
Go version (client): go1.4.1
Git commit (client): a8a31ef
OS/Arch (client): darwin/amd64
Server version: 1.5.0
Server API version: 1.17
Go version (server): go1.4.1
Git commit (server): a8a31ef
12345678910
12345678910
12345678910 上一篇:下一篇:文章评论相关解决方案 1234567891011 Copyright & &&版权所有node.js client for the Docker Registry API
A Docker Registry API client for node.js.
Limitations: Currently only support for Registry API v1
() pull support
(i.e. excluding API endpoints for push) and Registry API v2 pull support.
Support for v2 push endpoints is coming.
npm install docker-registry-client
Most usage of this package involves creating a Registry API client for a
specific repository and calling its methods.
A Registry client requires a repository name (called a repo in the code):
[INDEX/]NAME
# a &repo name&
# implies default index (docker.io) and namespace (library)
docker.io/mongo
# same thing
docker.io/library/mongo
# same thing
:5000/busybox
# a &busybox& repo on a private registry
quay.io/trentm/foo
# trentm&s &foo& repo on the quay.io service
The parseRepo function is used to parse these. See &examples/parseRepo.js&
to see how they are parsed:
$ node examples/parseRepo.js mongo
&index&: {
&name&: &docker.io&,
&official&: true
&official&: true,
&remoteName&: &library/mongo&,
&localName&: &mongo&,
&canonicalName&: &docker.io/mongo&
Commonly, a &repo name and tag& string is used for working with a Docker
registry, e.g. docker pull busybox:latest. The v2 API adds support for using
&repo name and digest& to stably identify images, e.g. docker pull alpine@sha256:fb9f1afa4d97caabfcecf0b0ce35c01dcb612f449739.
This package provides a parseRepoAndRef (and the synonym parseRepoAndTag)
for that, e.g.:
$ node examples/parseRepoAndRef.js :5000/busybox:foo
&index&: {
&name&: &:5000&,
&official&: false
&official&: false,
&remoteName&: &busybox&,
&localName&: &:5000/busybox&,
&canonicalName&: &:5000/busybox&,
&tag&: &foo&
Slightly different than docker.git&s parsing, this package allows the
scheme to be given on the index:
$ node examples/parseRepoAndRef.js https://quay.io/trentm/foo
&index&: {
&scheme&: &https&,
// &--- scheme
&name&: &quay.io&,
&official&: false
&official&: false,
&remoteName&: &trentm/foo&,
&localName&: &quay.io/trentm/foo&,
&canonicalName&: &quay.io/trentm/foo&,
&tag&: &latest&
// &--- default to &latest& tag
If a scheme isn&t given, then &https& is assumed.
If you know, for example, that you are only dealing with a v2 Docker Registry,
then simple usage will look like this:
var drc = require(&docker-registry-client&);
var REPO = &alpine&;
var client = drc.createClientV2({name: REPO});
client.listTags(function (err, tags) {
console.log(JSON.stringify(tags, null, 4));
* Because the client is typically using Keep-Alive, it will maintain
* open connections. Therefore you should call `.close()` to close
* those when finished.
client.close();
A more complete example (showing logging, auth, etc.):
var bunyan = require(&bunyan&);
var drc = require(&docker-registry-client&);
// This package uses /trentm/node-bunyan for logging.
var log = bunyan.createLogger({
name: &regplay&,
// TRACE-level logging will show you all request/response activity
// with the registry. This isn&t suggested for production usage.
level: &trace&
var REPO = &alpine&;
var client = drc.createClientV2({
name: REPO,
// Optional basic auth to the registry
username: &username&,
password: &password&,
// Optional, for a registry without a signed TLS certificate.
insecure: &true|false&,
// ... see the source code for other options
This package also supports the nominal technique for pinging the registry
to see if it supports v2, otherwise falling back to v1:
var drc = require(&docker-registry-client&);
var REPO = &alpine&;
drc.createClient({name: REPO, /* ... */}, function (err, client) {
console.log(&Got a Docker Registry API v%d client&, client.version);
A mapping of the
to the API
equivalents in this client lib. &NYI& means the endpoint is not yet implemented
by this client lib.
Description
Check that the endpoint implements Docker Registry API V2.
GET /v2/&name&/tags/list
Fetch the tags under the repository identified by name.
getManifest
GET /v2/&name&/manifests/&reference&
Fetch the manifest identified by name and reference where reference can be a tag or digest.
putManifest
PUT /v2/&name&/manifests/&reference&
NYI. Put the manifest identified by name and reference where reference can be a tag or digest.
deleteManifest
DELETE /v2/&name&/manifests/&reference&
NYI. Delete the manifest identified by name and reference where reference can be a tag or digest.
createBlobReadStream
GET /v2/&name&/blobs/&digest&
Retrieve the blob from the registry identified by digest.
HEAD /v2/&name&/blobs/&digest&
Retrieve the blob from the registry identified by digest -- just the headers.
startBlobUpload
POST /v2/&name&/blobs/uploads/
NYI. Initiate a resumable blob upload. If successful, an upload location will be provided to complete the upload. Optionally, if the digest parameter is present, the request body will be used to complete the upload in a single request.
getBlobUploadStatus
GET /v2/&name&/blobs/uploads/&uuid&
NYI. Retrieve status of upload identified by uuid. The primary purpose of this endpoint is to resolve the current status of a resumable upload.
uploadBlobChunk
PATCH /v2/&name&/blobs/uploads/&uuid&
NYI. Upload a chunk of data for the specified upload.
completeBlobUpload
PUT /v2/&name&/blobs/uploads/&uuid&
NYI. Complete the upload specified by uuid, optionally appending the body as the final chunk.
cancelBlobUpload
DELETE /v2/&name&/blobs/uploads/&uuid&
NYI. Cancel outstanding upload processes, releasing associated resources. If this is not called, the unfinished uploads will eventually timeout.
deleteBlob
DELETE /v2/&name&/blobs/&digest&
NYI. Delete the blob identified by name and digest. Warning: From the Docker spec I&m not sure that deleteBlob doesn&t corrupt images if you delete a shared blob.
listRepositories
GET /v2/_catalog/
NYI List all repositories in this registry.
for short code examples one can run from
the CLI for each API endpoint. E.g.:
$ npm install
# install dependencies for this module
$ node examples/v2/listTags.js busybox
&name&: &library/busybox&,
&buildroot-&,
&buildroot-2014.02&,
&ubuntu-12.04&,
&ubuntu-14.04&
You can also get logging on processing and HTTP requests/responses via the
-v option to the example scripts. This library uses
for logging, so you&ll
want to pipe the log output (on stderr) through the bunyan command for
pretty output:
$ node examples/v2/listTags.js -v busybox 2&&1 | ./node_modules/.bin/bunyan
[T22:26:44.065Z] TRACE: v2.listTags/registry/23400 on grape.local: request sent
GET /v2/ HTTP/1.1
Host: registry-1.docker.io
accept: application/json
user-agent: node-docker-registry-client/2.0.0 (x64- node/0.10.28)
date: Mon, 01 Jun :44 GMT
[T22:26:44.480Z] TRACE: v2.listTags/registry/23400 on grape.local: Response received (client_res={})
HTTP/1.1 401 Unauthorized
content-type: application/ charset=utf-8
docker-distribution-api-version: registry/2.0
www-authenticate: Bearer realm=&https://auth.docker.io/token&,service=&registry.docker.io&
date: Mon, 01 Jun :44 GMT
content-length: 114
connection: close
strict-transport-security: max-age=3153600
[T22:26:44.482Z] TRACE: v2.listTags/registry/23400 on grape.local:
body received:
{&errors&:[{&code&:&UNAUTHORIZED&,&message&:&access to the requested resource is not authorized&,&detail&:null}]}
[T22:26:44.485Z] TRACE: v2.listTags/registry/23400 on grape.local: login
[T22:26:44.487Z] DEBUG: v2.listTags/registry/23400 on grape.local: login: get Bearer auth token
[T22:26:45.680Z] TRACE: v2.listTags/registry/23400 on grape.local:
body received:
{&name&:&library/busybox&,&tags&:[&buildroot-&,&buildroot-2014.02&,&latest&,&ubuntu-12.04&,&ubuntu-14.04&]}
&name&: &library/busybox&,
&buildroot-&,
&buildroot-2014.02&,
&ubuntu-12.04&,
&ubuntu-14.04&
A mapping of the
to the API
equivalents in this client lib.
Limitation: Only the read endpoints of the v1 API are implement. I.e.
putting layers, deleting repositories, setting/deleting tags are all not
implemented.
Description
GET /v1/_ping
Check status of the registry.
GET /v1/search
Search the index.
listRepoImgs
GET /v1/repositories/$repo/images
List all images in this repo. This is actually against the
(aka &Hub API&).
listRepoTags
GET /v1/repositories/$repo/tags
List all tags for a repo.
getImgAncestry
GET /v1/images/$imgId/ancestry
Get the ancestry of an image.
getImgJson
GET /v1/images/$imgId/json
Get the metadata (sometimes called the &image JSON&) for an image.
getImgLayerStream
GET /v1/images/$imgId/layer
Download the image layer file.
PUT /v1/images/$imgId/layer
Not implemented. Put image layer.
DELETE /v1/repositories/$repo/tags/$tag
Not implemented. Delete a repo tag.
PUT /v1/repositories/$repo/tags/$tag
Not implemented. Set a repo tag.
DELETE /v1/repositories/$repo
Not implemented. Delete a repo.
for short code examples one can run from
the CLI for each API endpoint. E.g.:
$ npm install
# install dependencies for this module
$ node examples/v1/listRepoTags.js busybox
&buildroot-&: &3dba22db691e1f8cda4ca7b6b1b3bbad&,
&buildroot-2014.02&: &8c2eafb3d03b687e361cc43cf8ec1a4a725bc96e39f05ba97dd55&,
&latest&: &8c2eafb3d03b687e361cc43cf8ec1a4a725bc96e39f05ba97dd55&,
&ubuntu-12.04&: &faf804f0e07bfe4ca7c60acf2ffeab6efb48&,
&ubuntu-14.04&: &32e97f5f5d6bd15b9cc293b38a5102a7ddac53177a&
You can also get logging on processing and HTTP requests/responses via the
-v option to the example scripts. This library uses
for logging, so you&ll
want to pipe the log output (on stderr) through the bunyan command for
pretty output:
$ node listRepoTags.js -v busybox 2&&1 | bunyan
[T22:14:35.790Z] TRACE: listRepoTags/registry/13388 on danger0.local: get session token/cookie
[T22:14:35.836Z] TRACE: listRepoTags/registry/13388 on danger0.local: request sent
GET /v1/repositories/library/busybox/images HTTP/1.1
Host: index.docker.io
X-Docker-Token: true
accept: application/json
user-agent: node-docker-registry-client/2.0.0 (x64- node/0.10.40)
date: Wed, 02 Sep :35 GMT
[T22:14:36.374Z] TRACE: listRepoTags/registry/13388 on danger0.local: Response received (client_res={})
HTTP/1.1 200 OK
server: nginx/1.6.2
date: Wed, 02 Sep :36 GMT
[T22:14:37.888Z] TRACE: listRepoTags/registry/13388 on danger0.local:
body received:
{&buildroot-&: &3dba22db9...
[T22:14:37.888Z] TRACE: listRepoTags/registry/13388 on danger0.local: close http client (host=index.docker.io)
[T22:14:37.889Z] TRACE: listRepoTags/registry/13388 on danger0.local: close http client (host=registry-1.docker.io)
&buildroot-&: &3dba22db691e1f8cda4ca7b6b1b3bbad&,
&buildroot-2014.02&: &8c2eafb3d03b687e361cc43cf8ec1a4a725bc96e39f05ba97dd55&,
&latest&: &8c2eafb3d03b687e361cc43cf8ec1a4a725bc96e39f05ba97dd55&,
&ubuntu-12.04&: &faf804f0e07bfe4ca7c60acf2ffeab6efb48&,
&ubuntu-14.04&: &32e97f5f5d6bd15b9cc293b38a5102a7ddac53177a&
V1 client usage:
var repo = &alpine&;
var client = drc.createClientV1({
name: repo,
client.listRepoTags(function (err, repoTags) {
client.close();
if (err) {
console.log(err);
process.exit(1);
console.log(JSON.stringify(repoTags, null, 4));
For naming this package attempts to consistently use repo for repository,
img for image, etc.
T00:02:39.950Z
is the latest
of 24 releases
downloads in the last day
downloads in the last week
downloads in the last month
Have an issue?
Try it out
Dependencies (11)Docker 1.6.2 的 Client API 不支持stats了吗_百度知道java操作docker
Tag方法解释 - 开源中国社区
当前访客身份:游客 [
当前位置:
public void tagImage() throws Exception {
String tag = "" + RandomUtils.nextInt(Integer.MAX_VALUE);
dockerClient.tagImageCmd("busybox:latest", "docker-java/busybox", tag).exec();
dockerClient.removeImageCmd("docker-java/busybox:" + tag).exec();
这个方法中的 String tag = "" + RandomUtils.nextInt(Integer.MAX_VALUE); &中的 &双引号 就是 &空的吗?
还有这个 &dockerClient.tagImageCmd("busybox:latest", "docker-java/busybox", tag).exec();
中的“busybox:latest" &是 新的 镜像名吗?
那 "docker-java/busybox" &就是 &旧的镜像名吗?
共有3个答案
<span class="a_vote_num" id="a_vote_num_
1."" 是为了将生产的数值Int 转成字符串;
2.执行系统命令;
--- 共有 4 条评论 ---
(1年前)&nbsp&
: 就是不知道 到哪里找这个api....~~~~(&_&)~~~~。。你有关于java docker的api吗
(1年前)&nbsp&
: 具体你查一下API,我没有用Java调用。
(1年前)&nbsp&
那我说的那个镜像名
新旧 是对的吗?
(1年前)&nbsp&
<span class="a_vote_num" id="a_vote_num_
查资料看到了。。。
/reference/api/remote_api_client_libraries/
--- 共有 1 条评论 ---
(1年前)&nbsp&
<span class="a_vote_num" id="a_vote_num_
String tag = "" + RandomUtils.nextInt(Integer.MAX_VALUE);
是为了将随机产生的tag转成字符串;
“busybox:latest" & 是镜像名+tag,确定唯一的镜像,也可用镜像id来替代;
"docker-java/busybox" &是指新的镜像名
更多开发者职位上
有什么技术问题吗?
srhlwda...的其它问题
类似的话题Docker应用实践
摘要:最近几年,先有OpenStack引领云计算风潮,后有Docker来添砖加瓦,目前在国内云计算十分的火爆,多家IT巨头公司与创业公司等都选择云计算为新的发展方向。但事实上,很多企业只是因为Docker火爆才开始研究与测试,至于真正使用Docker解决某些问题或者提高工作效率,还未实现。
最近几年,先有OpenStack引领云计算风潮,后有Docker来添砖加瓦,目前在国内云计算十分的火爆,多家IT巨头公司与创业公司等都选择云计算为新的发展方向。但事实上,很多企业只是因为Docker火爆才开始研究与测试,至于真正使用Docker解决某些问题或者提高工作效率,还未实现。本文主要结合我自己互联网行业的工作实际向大家介绍我对Docker的认识,包括Docker真正适合做什么、如何使用Docker提高工作效率,供传统企业的运维人员参考。一、Dcoker应用场景总体来说,Docker适合轻量级应用比如web或者测试环境。我认为Docker的定位可以归纳为以下三点: 1、运维测试:使用Docker做沙箱,方便运维测试新软件或脚本测试;2、快速开发:方便开发人员快速地测试代码,使用Docker完成代码提交,并可以一键化测试;开发人员不需要关心如何部署服务、上传代码、打包等操作;3、集群应用:使用Docker+etcd+confd+haproxy等做集群,能快速进行auto_scale,保证了单点故障不影响整体服务,并且多主机资源能更多程度的利用。二、Docker企业平台化需求目前互联网技术发展日新月异,基本每天都有很多新的技术或者工具被研发出来。到底是否研究这个新的技术,需要理性判断。我一般研究新的技术,都是先整理好需求,然后过滤出满足我需求的软件,再进行细致的对比、分析和测试。在此过程中会查看软件是否有专门的社区、完整的文档,是不是处于不断的开发与维护bug中。当满足了这些需求我才会研究一门新技术,这样既能节省时间,也能快速找到合适的软件。&&& 如果企业想应用Docker,无论是在测试环境还是在生产环境,建议都先整理好需求,然后再看Docker本身是否有这些功能。即使Docker不具备某些功能,也可以看看是否可以通过插件或者自己开发来解决。只有当该产品能满足大部分需求,不能满足的部分也可以通过其他方法解决时,才是最适合自己使用,可以深入研究。以下是我整理出Docker企业应用平台的需求: 1、能WEB化进行容器操作,如创建、停止、开启、删除、详情查看、修改节点容器等操作;2、能动态的添加与删除容器的防火墙,不需要容器创建时使用-p功能;3、能为容器动态的绑定与解绑公网IP;4、能对容器镜像进行管理,可以进行镜像打包、镜像发布与镜像删除操作;5、能对宿主机节点进行管理,可以查看宿主机容器使用数据并进行资源分配控制;6、能动态对容器进行卷组的绑定与解绑;7、能对容器资源使用情况(如CPU使用率、内存使用量、网络使用量)进行监控与图形化显示;8、能实现区域管理;9、能实现半自动化代码自动部署,满足研发快速测试需求;10、使用auto_scale创建集群,能最大程度利用主机资源、高可用。&&& 上面10点就是我整理出Docker能实现的需求。虽然有一些需求Docker不直接支持,但可以通过自行开发程序来满足,所以我们才选择了深入研究Docker,并真正的在测试、生产环境使用起来。三、Docker平台功能介绍我从2014年5月开始研究Docker,同年9月完成1.0版本的Docker平台web化,11月份正式在生产环境使用,.0版本完成,实现研发半自动化持续部署与集群auto scale功能,可以说使用Docker时间比较长。以下简单图文介绍一下我所在企业的Docker平台功能。&1、容器管理主要能实现运维沙箱测试,可以web端创建容器,并进行cpu、内存、网络资源控制,以及ssh访问设置。&2、防火墙管理主要是可以动态的对现有的容器新增或者删除防火墙信息。3、公网IP管理容器可以通过绑定公网IP来让外边直接访问。此方法和Openstack绑定公网IP类似,是把公网IP绑定到计算节点,然后通过iptables的dnat与snat设置访问权限。&4、镜像管理主要是对私有库镜像查看、删除与推送(把已经在研发模式提交的镜像推送给集群节点)。&以下是某个镜像详情:宿主机管理可以查看当前区域宿主机信息(比如品牌、硬件型号、sn、ip等)以及容器数量。&6、卷组管理默认容器使用dm存储引擎,根分区10g,如果不满足需求,可以通过动态的绑定卷组来解决此问题。但如果想使用动态卷组,需要宿主机分区是ext4格式,否则不能实现。&7、资源监控管理可以查看容器的cpu、内存、网络资源使用信息。主要是使用Docker的api stats获取数据,然后写入到平台Mysql数据库里,然后前端通过ajax获取数据并使用highchart显示。8、密钥管理主要是让容器可以使用ssh进行登录,所以ssh使用密钥验证。可以新增rsa与dss的key,也可以自己上传key。9、项目开发管理主要是让研发可以快速的半自动化持续化部署与测试。下面是创建界面:新建开发项目,只需要输入对应信息后,就可以直接创建业务来测试,不需要部署服务与上次代码,更新的话,也可以点击一下鼠标来进行。如下:默认是latest版本,直接选择确定机是更新,输入版本号就是回滚。10、集群管理主要是包括负载均衡、高可用与auto scale。负载均衡是通过haproxy+keepalived实现,高可用是如果某节点的容器挂了,可以通过Docker自动启动;如果Docker挂了,可以通过systemctl自动启动;如果节点挂了,节点的容器ip会自动从lb里去除。可以看到有2个实例在运行,最大可以扩容到5个。PS:扩容与缩减的调整就是依赖cpu阀值与内存阀值,当此项目容器监控资源大于阀值就开始操作。集群更新的话,我这里是直接选择镜像来更新,回滚也一样,还可以直接选择回滚到上个版本。更新后前端会有1-2s中断,原因是新容器ip信息会发给前端lb,替换后用户会连接新的后端。四、Docker使用心得上述平台很多功能都不是Docker原生,都是通过程序结合Docker实现。我总结了一些Docker的使用心得,供大家参考。 1、持久化固定ipDocker默认使用bridge,给予容器的网络设备是eth0,然后此IP是通过dhcp获取的,当容器意外重启或挂掉后启动,容器的IP会重新获取。这种情况对于很多应用,比如数据库服务部署到Docker里,web应用连接因为容器IP变化导致无法连接,还有很多其他场景都要求使用固定IP。所以,我通过pipework+etcd+程序实现了持久化固定ip。主要通过自研脚本实现,在创建容器时候网络模式选择none模式,然后通过openvswitch创建网桥,通过pipework设置容器固定ip并存入etcd里;如果容器重启程序会从etcd获取ip并通过pipework重新分配此ip给容器。&&& 如下图:2、动态防火墙默认Docker是允许修改宿主机iptables的nat链,这样你在创建容器的时候,通过-p参数来指导nat信息,但这样有个缺点,不能对已经运行的容器修改防火墙信息,如果想修改只能先把当前宿主机防火墙策略保存,然后在去修改。所以我通过自研程序来进行动态修改防火墙功能,做法就是不允许Docker修改宿主机iptables,想做什么防火墙策略都是通过我的程序来修改宿主机iptables实现。3、绑定公网IP测试环境不需要公网IP,但如果是生产环境,肯定有场景需求,比如一个宿主机里n个容器,但有3个容器都想把自己80端口对公网,并且是80对80,但通过iptables只能满足一个容器80对80,所以得需要绑定额外的公网IP解决。4、资源监控我使用的资源监控就是通过Docker本身的api stats来获取数据,然后存入数据库,之前通过highchart进行图像展示。另外如果想通过zabbix监控也可以,能在zatree查看当前所有容器监控,如下图:5、半自动化持续部署与回滚以上介绍都是运维使用Docker进行测试,但怎么让研发也能加入进来,享受Docker带来的福利?这就是半自动化持续部署与回滚。使用Docker结合自定义程序,在配合jenkins或者直接使用maven打包,封装好了这些,配合web平台的界面,大大减少了研发与运维的交互,以及繁重的流程,让研发就开发即可。可以参考下图,是分析传统研发模式与Docker工作模式:可以看到Docker模式比传统模式减少了很多人力参与流程,节省更多时间,相应效率就会更高。用户创建完成项目后,后端会进行以下操作:启动容器=》分配固定ip=》资源限制=》下载代码之后就可以直接访问。 6、集群高可用与auto scale生产环境使用,必须是高可用与负载均衡的,否则某个容器或其宿主机挂了,就会影响业务。以下是集群架构:用户通过绑定的IP来访问负载均衡后面的容器,如果某节点挂了,IP会自动剔除。五、对传统行业应用Docker的建议&&&&&& &随着传统行业拥抱互联网,有些传统企业也开始尝试互联网技术包括Docker。以上介绍希望帮助大家对Docker的企业应用有一些了解。&&& 现在传统行业的IT厂商比如IBM正在全面支持Docker,推出Linux onPower服务器,利用Power服务器本身高性能和高RAS特性,来帮助传统企业更好地享受Docker带来的好处。综合历史积累、成本、人员等因素,选择商用产品和服务可能更适合现在传统行业的实际情况。在最后再次强调一下,如果企业想使用Docker,无论是用于测试还是生产环境,一定要先明确需求,判断其是否适用,然后再进行测试、研发或使用。如果有需求Docker满足不了,也无法通过插件或者自定义程序解决,不如选择其他软件。Docker并非万能,解决实际问题才是我们真正需要做的。阅读全文,请登录
把关者评语
文章问题讨论
咦?还没有人对这篇文章提问?来做第一个吧!
系统运维工程师,游戏公司

我要回帖

更多关于 docker stats源码详解 的文章

 

随机推荐