配置远程调用docker api的方法

docker默认只开了unix socket的方式进行api的调用,如下

[root@docker-master ~]# curl --unix-socket /var/run/docker.sock http:/v1.24/info
{"ID":"YHL4:JMNI:EXRN:S2M6:QFGE:S4D5:DQXT:FT5N:BSUM:NQDK:RAGE:JGKV","Containers":3,"ContainersRunning":2,"ContainersPaused":0,"ContainersStopped":1,"Images":16,"Driver":"devicemapper","DriverStatus":[["Pool Name","docker-253:2-68-pool"],["Pool Blocksize","65.54 kB"],["Base Device Size","10.74 GB"],["Backing Filesystem","xfs"],["Data file","/dev/loop0"],["Metadata file","/dev/loop1"],["Data Space Used","1.8 GB"],["Data Space Total","107.4 GB"],["Data Space Available","102.3 GB"],["Metadata Space Used","3.494 MB"],["Metadata Space Total","2.147 GB"],["Metadata Space Available","2.144 GB"],["Thin Pool Minimum Free Space","10.74 GB"],["Udev Sync Supported","true"],["Deferred Removal Enabled","false"],["Deferred Deletion Enabled","false"],["Deferred Deleted Device Count","0"],["Data loop file","/dmp/dockerData/devicemapper/devicemapper/data"],["Metadata loop file","/dmp/dockerData/devicemapper/devicemapper/metadata"],["Library Version","1.02.135-RHEL7 (2016-09-28)"]],"SystemStatus":null,"Plugins":{"Volume":["local"],"Network":["host","bridge","overlay","null"],"Authorization":null},"MemoryLimit":true,"SwapLimit":true,"KernelMemory":true,"CpuCfsPeriod":true,"CpuCfsQuota":true,"CPUShares":true,"CPUSet":true,"IPv4Forwarding":true,"BridgeNfIptables":true,"BridgeNfIp6tables":true,"Debug":false,"NFd":27,"OomKillDisable":true,"NGoroutines":33,"SystemTime":"2017-03-16T13:44:10.944251573+08:00","ExecutionDriver":"","LoggingDriver":"journald","CgroupDriver":"systemd","NEventsListener":0,"KernelVersion":"3.10.0-514.el7.x86_64","PkgVersion":"docker-common-1.12.5-14.el7.centos.x86_64","OperatingSystem":"CentOS Linux 7 (Core)","OSType":"linux","Architecture":"x86_64","IndexServerAddress":"https://index.docker.io/v1/","IndexServerName":"docker.io","RegistryConfig":{"InsecureRegistryCIDRs":["127.0.0.0/8"],"IndexConfigs":{"aostarit.io":{"Name":"aostarit.io","Mirrors":[],"Secure":false,"Official":false},"docker.io":{"Name":"docker.io","Mirrors":["http://26152e75.m.daocloud.io"],"Secure":true,"Official":true}},"Mirrors":["http://26152e75.m.daocloud.io"]},"NCPU":4,"MemTotal":8203071488,"DockerRootDir":"/dmp/dockerData","HttpProxy":"","HttpsProxy":"","NoProxy":"","Name":"docker-master","Labels":null,"ExperimentalBuild":false,"ServerVersion":"1.12.5","ClusterStore":"","ClusterAdvertise":"","SecurityOptions":["seccomp"],"Runtimes":{"docker-runc":{"path":"/usr/libexec/docker/docker-runc-current"},"runc":{"path":"docker-runc"}},"DefaultRuntime":"docker-runc","Swarm":{"NodeID":"","NodeAddr":"","LocalNodeState":"inactive","ControlAvailable":false,"Error":"","RemoteManagers":null,"Nodes":0,"Managers":0,"Cluster":{"ID":"","Version":{},"CreatedAt":"0001-01-01T00:00:00Z","UpdatedAt":"0001-01-01T00:00:00Z","Spec":{"Orchestration":{},"Raft":{},"Dispatcher":{},"CAConfig":{},"TaskDefaults":{}}}},"LiveRestoreEnabled":false,"Registries":[{"Name":"docker.io","Secure":true}]}
[root@docker-master ~]# 

 

现在开发要求远程也能调用,那么只需要在 /etc/sysconfig/docker中的option上面加上tcp的地址和端口,再重启docker即可

-H=unix:///var/run/docker.sock -H=tcp://docker-master:8888

[root@docker-master ~]# curl http://docker-master:8888/v1.24/info
{"ID":"YHL4:JMNI:EXRN:S2M6:QFGE:S4D5:DQXT:FT5N:BSUM:NQDK:RAGE:JGKV","Containers":3,"ContainersRunning":2,"ContainersPaused":0,"ContainersStopped":1,"Images":16,"Driver":"devicemapper","DriverStatus":[["Pool Name","docker-253:2-68-pool"],["Pool Blocksize","65.54 kB"],["Base Device Size","10.74 GB"],["Backing Filesystem","xfs"],["Data file","/dev/loop0"],["Metadata file","/dev/loop1"],["Data Space Used","1.8 GB"],["Data Space Total","107.4 GB"],["Data Space Available","102.3 GB"],["Metadata Space Used","3.494 MB"],["Metadata Space Total","2.147 GB"],["Metadata Space Available","2.144 GB"],["Thin Pool Minimum Free Space","10.74 GB"],["Udev Sync Supported","true"],["Deferred Removal Enabled","false"],["Deferred Deletion Enabled","false"],["Deferred Deleted Device Count","0"],["Data loop file","/dmp/dockerData/devicemapper/devicemapper/data"],["Metadata loop file","/dmp/dockerData/devicemapper/devicemapper/metadata"],["Library Version","1.02.135-RHEL7 (2016-09-28)"]],"SystemStatus":null,"Plugins":{"Volume":["local"],"Network":["null","host","bridge","overlay"],"Authorization":null},"MemoryLimit":true,"SwapLimit":true,"KernelMemory":true,"CpuCfsPeriod":true,"CpuCfsQuota":true,"CPUShares":true,"CPUSet":true,"IPv4Forwarding":true,"BridgeNfIptables":true,"BridgeNfIp6tables":true,"Debug":false,"NFd":28,"OomKillDisable":true,"NGoroutines":34,"SystemTime":"2017-03-16T13:45:55.321032558+08:00","ExecutionDriver":"","LoggingDriver":"journald","CgroupDriver":"systemd","NEventsListener":0,"KernelVersion":"3.10.0-514.el7.x86_64","PkgVersion":"docker-common-1.12.5-14.el7.centos.x86_64","OperatingSystem":"CentOS Linux 7 (Core)","OSType":"linux","Architecture":"x86_64","IndexServerAddress":"https://index.docker.io/v1/","IndexServerName":"docker.io","RegistryConfig":{"InsecureRegistryCIDRs":["127.0.0.0/8"],"IndexConfigs":{"aostarit.io":{"Name":"aostarit.io","Mirrors":[],"Secure":false,"Official":false},"docker.io":{"Name":"docker.io","Mirrors":["http://26152e75.m.daocloud.io"],"Secure":true,"Official":true}},"Mirrors":["http://26152e75.m.daocloud.io"]},"NCPU":4,"MemTotal":8203071488,"DockerRootDir":"/dmp/dockerData","HttpProxy":"","HttpsProxy":"","NoProxy":"","Name":"docker-master","Labels":null,"ExperimentalBuild":false,"ServerVersion":"1.12.5","ClusterStore":"","ClusterAdvertise":"","SecurityOptions":["seccomp"],"Runtimes":{"docker-runc":{"path":"/usr/libexec/docker/docker-runc-current"},"runc":{"path":"docker-runc"}},"DefaultRuntime":"docker-runc","Swarm":{"NodeID":"","NodeAddr":"","LocalNodeState":"inactive","ControlAvailable":false,"Error":"","RemoteManagers":null,"Nodes":0,"Managers":0,"Cluster":{"ID":"","Version":{},"CreatedAt":"0001-01-01T00:00:00Z","UpdatedAt":"0001-01-01T00:00:00Z","Spec":{"Orchestration":{},"Raft":{},"Dispatcher":{},"CAConfig":{},"TaskDefaults":{}}}},"LiveRestoreEnabled":false,"Registries":[{"Name":"docker.io","Secure":true}]}
[root@docker-master ~]# 

 

posted @ 2017-03-16 13:47  纳兹波蛋  阅读(3210)  评论(0编辑  收藏  举报