为了账号安全,请及时绑定邮箱和手机立即绑定

关于docker rest api接口组件docker remote api的使用

标签:
Docker

前提:

     docker remote api 是docker自带的一个rest api 管理。

     只要在配置文件里面申明下就可以了。

下面是docker remote api的官方的功能目录:

Docker Remote API v1.3

3.1 Inside ‘docker run’

3.2 Hijacking

3.3 CORS Requests

2.1 Containers

2.2 Images

2.3 Misc

List containers

Create a container

Inspect a container

List processes running inside a container

Inspect changes on a container’s filesystem

Export a container

Start a container

Stop a contaier

Restart a container

Kill a container

Attach to a container

Wait a container

Remove a container

List Images

Create an p_w_picpath

Insert a file in a p_w_picpath

Inspect an p_w_picpath

Get the history of an p_w_picpath

Push an p_w_picpath on the registry

Tag an p_w_picpath into a repository

Remove an p_w_picpath

Search p_w_picpaths

Build an p_w_picpath from Dockerfile via stdin

Check auth configuration

Display system-wide information

Show the docker version information

Create a new p_w_picpath from a container’s changes

Monitor Docker’s events

1. Brief introduction

2. Endpoints

3. Going further

wKiom1PrcYvTKgqfAAD_lg8pjg8050.jpg

通过接口获取所有的镜像 !

[root@dev-ops ~]$curl 'http://127.0.0.1:4243/p_w_picpaths/json?all=0'| python -m json.tool 

原文:   

[

    {

        "Created": 1407902496,

        "Id": "57672d1b597912c7b6841c05c0e07e525890cfd64cbd37c84754e7d7e54ee766",

        "ParentId": "47386e322f5deffbc04c777632e1f1ac7e6ddd6909ae6b9ce8d1d78dc2bb6d0c",

        "RepoTags": [

            "ubuntu_redis:latest"

        ],

        "Size": 2675587,

        "VirtualSize": 257554797

    },

    {

        "Created": 1407684299,

        "Id": "636d86f228c7c6e844d1473245a9580d9c57fd0bfd1b5b9172aa5c168581978c",

        "ParentId": "e882dd610d1ca64817106dcbda29b2c78536f5fb75f780583cc9fac0efe05398",

        "RepoTags": [

            "rastasheep/ubuntu-sshd:14.04"

        ],

        "Size": 0,

        "VirtualSize": 254925704

    },

    {

        "Created": 1407342004,

        "Id": "1147568d245b369495b19b1943c0946a2b2d823d0a96b48bb7bee5f128090d29",

        "ParentId": "12175cbcbe499c80dd71e3085467d9178a1b5cfa47ecf1463302e09fe2f09e58",

        "RepoTags": [

            "rastasheep/ubuntu-sshd:12.04"

        ],

        "Size": 0,

        "VirtualSize": 144645266

    },

    {

        "Created": 1407341844,

        "Id": "8a63145eed52cf9ae6bdb064f370469d6fa3653f0da5d370ece9e270baf8d9cb",

        "ParentId": "ca60f67629d2c43012fb53f714e60672c4ad5b61520bb306e3a35614190dcf76",

        "RepoTags": [

            "rastasheep/ubuntu-sshd:13.10"

        ],

        "Size": 0,

        "VirtualSize": 231639963

    },

    {

        "Created": 1407167259,

        "Id": "47386e322f5deffbc04c777632e1f1ac7e6ddd6909ae6b9ce8d1d78dc2bb6d0c",

        "ParentId": "a8bbc54283bbc341c703970ed429e4def6c034273ede59aaf451449164c95775",

        "RepoTags": [

            "rastasheep/ubuntu-sshd:latest"

        ],

        "Size": 0,

        "VirtualSize": 254879210

    },

    {

        "Created": 1406884906,

        "Id": "b78c71c001db87eb2da7049f5f9610039afd3484f65e22a3284098792460040d",

        "ParentId": "e13b39edfcb4c5e15f876c2824fea1d738fb3825437162fad497138123f3235b",

        "RepoTags": [

            "lemonbar/centos6-ssh:latest"

        ],

        "Size": 0,

        "VirtualSize": 296869021

    },

    {

        "Created": 1405333140,

        "Id": "c9c48c3cb34c4b8305d7bae4f0c3c753fbca3ac96195e73e9fdab4a8fa24708a",

        "ParentId": "30ffc511bbe11f6205cdc0f2749cadcc0c2eca4f7296285b1af867afcb6ef842",

        "RepoTags": [

            "rastasheep/ubuntu-sshd:12.10"

        ],

        "Size": 0,

        "VirtualSize": 188947523

    },

    {

        "Created": 1405333120,

        "Id": "bf49ae3d55344648b354bddf22b2f15c48e2d74e52933404757a9eb470ac35e3",

        "ParentId": "561b2d67fd0a80367e9ab98f9893ce6d36006dbb452e7c8693f028fcaa5f6c7f",

        "RepoTags": [

            "rastasheep/ubuntu-sshd:13.04"

        ],

        "Size": 0,

        "VirtualSize": 213124480

    }]

原文: http://rfyiamcool.blog.51cto.com/1030776/1539677     

#这里是查看已经启动了的docker容器情况 !

root@dev-ops:~# curl http://127.0.0.1:4243/containers/json | python -m json.tool

[

    {

        "Command": "/usr/sbin/sshd -D",

        "Created": 1407902166,

        "Id": "df7b7568fa7a8c65e7ce857378a01ed127109b4de5e6508123e4797a5c54bfbe",

        "Image": "rastasheep/ubuntu-sshd:latest",

        "Names": [

            "/test_sshd"

        ],

        "Ports": [

            {

                "IP": "0.0.0.0",

                "PrivatePort": 22,

                "PublicPort": 49153,

                "Type": "tcp"

            }

        ],

        "Status": "Up 3 hours"

    }

]

#查看某个容器的具体信息

root@dev-ops:~# curl -XGET 'http://127.0.0.1:4243/containers/df7b7568fa7a/json' | python -m json.tool

{

    "Args": [

        "-D"

    ],

    "Config": {

        "AttachStderr": false,

        "AttachStdin": false,

        "AttachStdout": false,

        "Cmd": [

            "/usr/sbin/sshd",

            "-D"

        ],

        "CpuShares": 0,

        "Dns": null,

        "Domainname": "",

        "Entrypoint": null,

        "Env": [

            "HOME=/",

            "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

        ],

        "ExposedPorts": {

            "22/tcp": {}

        },

        "Hostname": "df7b7568fa7a",

        "Image": "rastasheep/ubuntu-sshd",

        "Memory": 0,

        "MemorySwap": 0,

        "NetworkDisabled": false,

        "OnBuild": null,

        "OpenStdin": false,

        "PortSpecs": null,

        "StdinOnce": false,

        "Tty": false,

        "User": "",

        "Volumes": null,

        "VolumesFrom": "",

        "WorkingDir": ""

    },

    "Created": "2014-08-13T03:56:06.602313986Z",

    "Driver": "aufs",

    "ExecDriver": "native-0.1",

    "HostConfig": {

        "Binds": null,

        "ContainerIDFile": "",

        "Links": null,

        "LxcConf": [],

        "PortBindings": {

            "22/tcp": [

                {

                    "HostIp": "0.0.0.0",

                    "HostPort": "49153"

                }

            ]

        },

        "Privileged": false,

        "PublishAllPorts": true

    },

    "HostnamePath": "/var/lib/docker/containers/df7b7568fa7a8c65e7ce857378a01ed127109b4de5e6508123e4797a5c54bfbe/hostname",

    "HostsPath": "/var/lib/docker/containers/df7b7568fa7a8c65e7ce857378a01ed127109b4de5e6508123e4797a5c54bfbe/hosts",

    "ID": "df7b7568fa7a8c65e7ce857378a01ed127109b4de5e6508123e4797a5c54bfbe",

    "Image": "47386e322f5deffbc04c777632e1f1ac7e6ddd6909ae6b9ce8d1d78dc2bb6d0c",

    "Name": "/test_sshd",

    "NetworkSettings": {

        "Bridge": "docker0",

        "Gateway": "172.17.42.1",

        "IPAddress": "172.17.0.3",

        "IPPrefixLen": 16,

        "PortMapping": null,

        "Ports": {

            "22/tcp": [

                {

                    "HostIp": "0.0.0.0",

                    "HostPort": "49153"

                }

            ]

        }

    },

    "Path": "/usr/sbin/sshd",

    "ResolvConfPath": "/etc/resolv.conf",

    "State": {

        "ExitCode": 0,

        "FinishedAt": "2014-08-13T06:42:46.204526996Z",

        "Ghost": false,

        "Pid": 4222,

        "Running": true,

        "StartedAt": "2014-08-13T06:42:46.225958747Z"

    },

    "Volumes": {},

    "VolumesRW": {}

}

创建一个容器 !

[root@dev-ops ~]$curl -XPOST -H "Content-Type: application/json"  http://127.0.0.1:4243/containers/create -d '{ 

     "Hostname":"", 

     "User":"", 

     "Memory":0, 

     "MemorySwap":0, 

     "AttachStdin":false, 

     "AttachStdout":true, 

     "AttachStderr":true, 

     "PortSpecs":null, 

     "Privileged": false, 

     "Tty":false, 

     "OpenStdin":false, 

     "StdinOnce":false, 

     "Env":null, 

     "Dns":null, 

     "Image":"rastasheep/ubuntu-sshd", 

     "Volumes":{}, 

     "VolumesFrom":"", 

     "WorkingDir":"" 

}' 

{"Id":"d0274fdba510f643a0398cac36ee4caf9615b74e72452ff22951c96697f22c29","Warnings":null}

可能会返回的状态 !

config – the container’s configuration

Status Codes:

201 – no error

404 – no such container

406 – impossible to attach (container not running)

500 – server error

#我们查看下结果

[root@dev-ops ~]$docker ps -a

CONTAINER ID        IMAGE                           COMMAND             CREATED              STATUS              PORTS                            NAMES

d0274fdba510        rastasheep/ubuntu-sshd:latest   /usr/sbin/sshd -D   About a minute ago   Up 7 seconds        22/tcp                           silly_turing        

2602cb4fb43b        rastasheep/ubuntu-sshd:latest   /usr/sbin/sshd -D   2 minutes ago        Up 56 seconds       22/tcp                           angry_lovelace      

1d20403be200        ubuntu_redis:latest             /usr/sbin/sshd -D   3 hours ago          Up 3 minutes        22/tcp, 0.0.0.0:6379->6379/tcp   redis_6379          

c5f6d0240531        ubuntu_redis:latest             /usr/sbin/sshd -D   6 hours ago          Exit 0                                               redis_sshd          

df7b7568fa7a        rastasheep/ubuntu-sshd:latest   /usr/sbin/sshd -D   6 hours ago          Up 3 hours          0.0.0.0:49153->22/tcp            test_sshd

查看容器内的top信息:

wKioL1PrdmSxycPkAAGX9o6qI90787.jpg

原文: http://rfyiamcool.blog.51cto.com/1030776/1539677 

关闭容器,启动容器:

root@dev-ops:~# curl -s -XPOST "http://127.0.0.1:4243/containers/d0274fdba510/stop" 

root@dev-ops:~# 

root@dev-ops:~# curl -s -XPOST "http://127.0.0.1:4243/containers/d0274fdba510/start"

wKiom1PrdDTQs0bAAAO4vClEaqk448.jpg

我这边就简单说下,详细的功能实现大家自己翻墙到官网look下吧。 说来也怪,docker时不时的抽风被墙 。我看了国外的论坛,貌似有些公司做了基于docker remote api实现的管理平台。   

©著作权归作者所有:来自51CTO博客作者rfyiamcool的原创作品,谢绝转载,否则将追究法律责任

docker apidocker remote apipython应用


点击查看更多内容
TA 点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
  • 推荐
  • 评论
  • 收藏
  • 共同学习,写下你的评论
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消