docker的C/S模式
remote API
restful风格
STDIN\STDOUT\STDERROR
官方文档
https://docs.docker.com/engine/reference/api/docker_remote_api/
连接方式
通过socket连接
unix:///var/run/docker.sock默认
tcp://host:port
fd://socketfd
user-------cli/app------docker client-------------socket--------docker server
root@eddy:~# ps -ef|grep docker
root 1307 1 0 18:36 ? 00:00:00 /usr/bin/docker daemon --registry-mirror=http://d9768597.m.daocloud.io
root@eddy:~# docker version
Client:
Version: 1.9.1
API version: 1.21
Go version: go1.4.2
Git commit: a34a1d5
Built: Fri Nov 20 13:12:04 UTC 2015
OS/Arch: linux/amd64
Server:
Version: 1.9.1
API version: 1.21
Go version: go1.4.2
Git commit: a34a1d5
Built: Fri Nov 20 13:12:04 UTC 2015
OS/Arch: linux/amd64
root@eddy:~# telnet 192.168.1.100 2375
Trying 192.168.1.100...
Connected to 192.168.1.100.
Escape character is '^]'.
GET /info HTTP/1.1
HTTP/1.1 200 OK
Content-Type: application/json
Server: Docker/1.9.1 (linux)
Date: Sun, 24 Jan 2016 11:21:40 GMT
Content-Length: 1255
{"ID":"ETBV:KVRN:2RBL:CQ4M:WRHA:WF6O:6O7Z:KHPZ:LTX6:6ZLC:GC2B:TVU2","Containers":10,"Images":10,"Driver":"aufs","DriverStatus":[["Root Dir","/var/lib/docker/aufs"],["Backing Filesystem","extfs"],["Dirs","31"],["Dirperm1 Supported","false"]],"MemoryLimit":true,"SwapLimit":false,"CpuCfsPeriod":true,"CpuCfsQuota":true,"IPv4Forwarding":true,"BridgeNfIptables":true,"BridgeNfIp6tables":true,"Debug":false,"NFd":13,"OomKillDisable":true,"NGoroutines":20,"SystemTime":"2016-01-24T19:21:40.018829573+08:00","ExecutionDriver":"native-0.2","LoggingDriver":"json-file","NEventsListener":0,"KernelVersion":"3.13.0-24-generic","OperatingSystem":"Ubuntu 14.04 LTS","IndexServerAddress":"https://index.docker.io/v1/","RegistryConfig":{"InsecureRegistryCIDRs":["127.0.0.0/8"],"IndexConfigs":{"docker.io":{"Name":"docker.io","Mirrors":["http://d9768597.m.daocloud.io/"],"Secure":true,"Official":true}},"Mirrors":["http://d9768597.m.daocloud.io/"]},"InitSha1":"4fc7c03a06c675f115b39958c13486d53df10a14","InitPath":"/usr/lib/docker/dockerinit","NCPU":1,"MemTotal":1034764288,"DockerRootDir":"/var/lib/docker","HttpProxy":"","HttpsProxy":"","NoProxy":"","Name":"eddy","Labels":null,"ExperimentalBuild":false,"ServerVersion":"1.9.1","ClusterStore":"","ClusterAdvertise":""}
docker守护进程的配置和操作
root@eddy:~# service docker stop
root@eddy:~# service docker start
root@eddy:~# service docker restart
root@eddy:~# status docker
docker的启动选项
docker -d options
root@eddy:~# docker daemon --help
Usage: docker daemon [OPTIONS]
Enable daemon mode
--api-cors-header= Set CORS headers in the remote API
-b, --bridge= Attach containers to a network bridge
--bip= Specify network bridge IP
--cluster-advertise= Address or interface name to advertise
--cluster-store= Set the cluster store
--cluster-store-opt=map[] Set cluster store options
-D, --debug=false Enable debug mode
--default-gateway= Container default gateway IPv4 address
--default-gateway-v6= Container default gateway IPv6 address
--default-ulimit=[] Set default ulimits for containers
--disable-legacy-registry=false Do not contact legacy registries
--dns=[] DNS server to use
--dns-opt=[] DNS options to use
--dns-search=[] DNS search domains to use
-e, --exec-driver=native Exec driver to use
--exec-opt=[] Set exec driver options
--exec-root=/var/run/docker Root of the Docker execdriver
--fixed-cidr= IPv4 subnet for fixed IPs
--fixed-cidr-v6= IPv6 subnet for fixed IPs
-G, --group=docker Group for the unix socket
-g, --graph=/var/lib/docker Root of the Docker runtime
-H, --host=[] Daemon socket(s) to connect to
--help=false Print usage
--icc=true Enable inter-container communication
--insecure-registry=[] Enable insecure registry communication
--ip=0.0.0.0 Default IP when binding container ports
--ip-forward=true Enable net.ipv4.ip_forward
--ip-masq=true Enable IP masquerading
--iptables=true Enable addition of iptables rules
--ipv6=false Enable IPv6 networking
-l, --log-level=info Set the logging level
--label=[] Set key=value labels to the daemon
--log-driver=json-file Default driver for container logs
--log-opt=map[] Set log driver options
--mtu=0 Set the containers network MTU
-p, --pidfile=/var/run/docker.pid Path to use for daemon PID file
--registry-mirror=[] Preferred Docker registry mirror
-s, --storage-driver= Storage driver to use
--selinux-enabled=false Enable selinux support
--storage-opt=[] Set storage driver options
--tls=false Use TLS; implied by --tlsverify
--tlscacert=~/.docker/ca.pem Trust certs signed only by this CA
--tlscert=~/.docker/cert.pem Path to TLS certificate file
--tlskey=~/.docker/key.pem Path to TLS key file
--tlsverify=false Use TLS and verify the remote
--userland-proxy=true Use userland proxy for loopback traffic
配置文件
root@eddy:~# vim /etc/default/docker
DOCKER_OPTS="--registry-mirror=http://X.X.X.X -H tcp://0.0.0.0:2375"
重启服务
root@eddy:~# ps -ef|grep docker
root 9970 1 0 19:18 ? 00:00:00 /usr/bin/docker daemon --registry-mirror=http://d9768597.m.daocloud.io -H tcp://0.0.0.0:2375
docker的远程访问
环境准备
第二台安装docker的服务器
修改docker守护进程的启动选项区别服务器
保证client API和server API版本一致
curl http://192.168.1.100:2375/info
{"ID":"ETBV:KVRN:2RBL:CQ4M:WRHA:WF6O:6O7Z:KHPZ:LTX6:6ZLC:GC2B:TVU2","Containers":10,"Images":10,"Driver":"aufs","DriverStatus":[["Root Dir","/var/lib/docker/aufs"],["Backing Filesystem","extfs"],["Dirs","31"],["Dirperm1 Supported","false"]],"MemoryLimit":true,"SwapLimit":false,"CpuCfsPeriod":true,"CpuCfsQuota":true,"IPv4Forwarding":true,"BridgeNfIptables":true,"BridgeNfIp6tables":true,"Debug":false,"NFd":13,"OomKillDisable":true,"NGoroutines":20,"SystemTime":"2016-01-24T19:16:48.515327038+08:00","ExecutionDriver":"native-0.2","LoggingDriver":"json-file","NEventsListener":0,"KernelVersion":"3.13.0-24-generic","OperatingSystem":"Ubuntu 14.04 LTS","IndexServerAddress":"https://index.docker.io/v1/","RegistryConfig":{"InsecureRegistryCIDRs":["127.0.0.0/8"],"IndexConfigs":{"docker.io":{"Name":"docker.io","Mirrors":["http://d9768597.m.daocloud.io/"],"Secure":true,"Official":true}},"Mirrors":["http://d9768597.m.daocloud.io/"]},"InitSha1":"4fc7c03a06c675f115b39958c13486d53df10a14","InitPath":"/usr/lib/docker/dockerinit","NCPU":1,"MemTotal":1034764288,"DockerRootDir":"/var/lib/docker","HttpProxy":"","HttpsProxy":"","NoProxy":"","Name":"eddy","Labels":null,"ExperimentalBuild":false,"ServerVersion":"1.9.1","ClusterStore":"","ClusterAdvertise":""}
修改客户端配置
root@eddy:~# docker -H tcp://192.168.1.100:2375 info
Containers: 10
Images: 10
Server Version: 1.9.1
Storage Driver: aufs
Root Dir: /var/lib/docker/aufs
Backing Filesystem: extfs
Dirs: 31
Dirperm1 Supported: false
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 3.13.0-24-generic
Operating System: Ubuntu 14.04 LTS
CPUs: 1
Total Memory: 986.8 MiB
Name: eddy
ID: ETBV:KVRN:2RBL:CQ4M:WRHA:WF6O:6O7Z:KHPZ:LTX6:6ZLC:GC2B:TVU2
WARNING: No swap limit support
环境变量
root@eddy:~# docker info
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
直接输入将不能访问
如果每一次都要输入-H选项将相当麻烦这里使用一个环境变量
root@eddy:~# export DOCKER_HOST="tcp://192.168.1.100:2375"
root@eddy:~# docker info
Containers: 10
Images: 10
Server Version: 1.9.1
Storage Driver: aufs
Root Dir: /var/lib/docker/aufs
Backing Filesystem: extfs
Dirs: 31
Dirperm1 Supported: false
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 3.13.0-24-generic
Operating System: Ubuntu 14.04 LTS
CPUs: 1
Total Memory: 986.8 MiB
Name: eddy
ID: ETBV:KVRN:2RBL:CQ4M:WRHA:WF6O:6O7Z:KHPZ:LTX6:6ZLC:GC2B:TVU2
WARNING: No swap limit support
在服务端执行docker info也不行,因为启动时候加了远程访问选项这里继续修改docker配置文件
DOCKER_OPTS="--registry-mirror=http://d9768597.m.daocloud.io -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock"
在加上默认方式
这样在服务端也可以使用docker info了
转载于:https://my.oschina.net/eddylinux/blog/609261