首先直奔主题,看看Docker Cloud的几大关键性功能:
而在今天的文章中,我们将探讨:
最后,我们还将共享部分Docker Cloud参考文档。
本文将使用Couchbase Server——一套面向Docker镜像的开源、高扩展性、JSON文件数据库。
下面来看如何在Amazon中利用Docker Cloud运行Docker镜像:
brew install docker-cloud docker-cloud nodecluster create -t 1 --tag couchbase couchbase-node aws us-west-1 m3.large docker-cloud service create --tag couchbase -p 8091:8091 -p 8092:8092 -p 8093:8093 -p 11210:11210 arungupta/couchbase docker-cloud service start {SERVICE_ID} docker-cloud service inspect {SERVICE_ID} | jq ".container_ports[0].endpoint_uri" | sed 's/tcp/http/g'
接着开始具体探讨。
Docker Cloud可通过Web、CLI或者REST API进行托管。本文将利用Docker Cloud CLI执行各项命令。
安装Docker Cloud CLI:
brew install docker-cloud ==> Downloading https://homebrew.bintray.com/bottles/docker-cloud-1.0.2.yosemite.bottle.tar.gz Already downloaded: /Library/Caches/Homebrew/docker-cloud-1.0.2.yosemite.bottle.tar.gz ==> Pouring docker-cloud-1.0.2.yosemite.bottle.tar.gz �� /usr/local/Cellar/docker-cloud/1.0.2: 482 files, 4.1M
更为完整的安装操作请参阅“安装CLI”一文。
检查版本:
docker-cloud -v docker-cloud 1.0.2
完整的命令内容如下:
usage: docker-cloud [-h] [-v] {action,container,event,exec,login,node,nodecluster,repository,run,service,stack,tag,trigger,up} ... Docker Cloud CLI optional arguments: -h, --help show this help message and exit -v, --version show program's version number and exit Docker Cloud CLI commands: {action,container,event,exec,login,node,nodecluster,repository,run,service,stack,tag,trigger,up} action Action-related operations container Container-related operations event Get real time Docker Cloud events exec Run a command in a running container login Please use "docker login" to log into Docker Cloud node Node-related operations nodecluster NodeCluster-related operations repository Repository-related operations run Create and run a new service service Service-related operations stack Stack-related operations tag Tag-related operations trigger Trigger-related operations up Create and deploy a stack
保存并登录凭证:
docker login Username: arungupta Password: Email: arun.gupta@gmail.com WARNING: login credentials saved in /Users/arungupta/.docker/config.json Login Succeeded
根据云服务供应商相关说明链接利用Docker Cloud Web UI注册您的云供应商证书。目前支持Amazon、Digital Ocean、Azure等主流供应商。
利用单一节点创建一套节点集群:
docker-cloud nodecluster create -t 1 --tag couchbase couchbase-node aws us-west-1 m3.large 42a34e04-02e1-47be-bf87-ec06e0e0b604
此节点拥有一个节点(-t 1),且使用标签“couchbase” (--tag couchbase)。最后四条参数分别代表节点集群名称(couchbase-node)、供应商(aws)、区域(us-west-1)以及节点类型(m3.large)。
此节点集群中的每个节点都将分配有标签,并用于随后将服务指定至特定节点或者节点集群。
此节点集群的运行状态如下:
docker-cloud nodecluster inspect 42a34e04-02e1-47be-bf87-ec06e0e0b604 | jq { "disk": 60, "uuid": "42a34e04-02e1-47be-bf87-ec06e0e0b604", "tags": [ { "name": "couchbase" } ], "current_num_nodes": 1, "region": "/api/infra/v1/region/aws/us-west-1/", "target_num_nodes": 1, "state": "Deployed", "node_type": "/api/infra/v1/nodetype/aws/m3.large/", "resource_uri": "/api/infra/v1/nodecluster/42a34e04-02e1-47be-bf87-ec06e0e0b604/", "destroyed_datetime": null, "provider_options": {}, "nodes": [ "/api/infra/v1/node/5c4c78e0-71c9-4420-9a1d-fdb04a35d1de/" ], "deployed_datetime": "Tue, 15 Mar 2016 17:18:17 +0000", "nickname": "couchbase-node", "dockercloud_action_uri": "", "name": "couchbase-node" }
亦可查看更多关于各个节点的具体信息:
创建一项Docker Cloud服务:
docker-cloud service create -p 8091:8091 -p 8092:8092 -p 8093:8093 -p 11210:11210 arungupta/couchbase 834343fd-b1d5-4d66-a2cd-69d27a471658
如果存在多个节点集群,则可使用--tag将一项服务分配至一套节点集群。
docker-cli#10字段旨在确保多个端口可通过-p 8091-8093:8091-8093格式进行公开。
这里使用的Docker镜像为arungupta/couchbase。此镜像基于Docker Hub上的官方couchbase镜像,且针对不同服务进行了预配置。
docker-cloud service start 834343fd-b1d5-4d66-a2cd-69d27a471658 834343fd-b1d5-4d66-a2cd-69d27a471658
更新后的仪表板如下:
docker-cloud service logs 834343fd-b1d5-4d66-a2cd-69d27a471658 couchbase-d96eed5d-1 | 2016-03-14T22:54:04.826000846Z Starting Couchbase Server -- Web UI available at http://:8091 couchbase-d96eed5d-1 | 2016-03-14T22:54:19.832855273Z * Trying 127.0.0.1... couchbase-d96eed5d-1 | 2016-03-14T22:54:19.833816400Z % Total % Received % Xferd Average Speed Time Time Time Current couchbase-d96eed5d-1 | 2016-03-14T22:54:19.834647384Z Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to 127.0.0.1 (127.0.0.1) port 8091 (#0) couchbase-d96eed5d-1 | 2016-03-14T22:54:19.835659864Z > POST /pools/default HTTP/1.1 couchbase-d96eed5d-1 | 2016-03-14T22:54:19.835705633Z > User-Agent: curl/7.40.0-DEV couchbase-d96eed5d-1 | 2016-03-14T22:54:19.835764766Z > Host: 127.0.0.1:8091 couchbase-d96eed5d-1 | 2016-03-14T22:54:19.835808491Z > Accept: */* couchbase-d96eed5d-1 | 2016-03-14T22:54:19.835849972Z > Content-Length: 36 couchbase-d96eed5d-1 | 2016-03-14T22:54:19.835890805Z > Content-Type: application/x-www-form-urlencoded couchbase-d96eed5d-1 | 2016-03-14T22:54:19.835951739Z > couchbase-d96eed5d-1 | 2016-03-14T22:54:19.836153748Z } [36 bytes data] couchbase-d96eed5d-1 | 2016-03-14T22:54:19.836431490Z * upload completely sent off: 36 out of 36 bytes couchbase-d96eed5d-1 | 2016-03-14T22:54:19.838702601Z < HTTP/1.1 200 OK couchbase-d96eed5d-1 | 2016-03-14T22:54:19.838831946Z < Server: Couchbase Server couchbase-d96eed5d-1 | 2016-03-14T22:54:19.838882039Z < Pragma: no-cache couchbase-d96eed5d-1 | 2016-03-14T22:54:19.838929456Z < Date: Mon, 14 Mar 2016 22:54:19 GMT couchbase-d96eed5d-1 | 2016-03-14T22:54:19.838944199Z < Content-Length: 0 couchbase-d96eed5d-1 | 2016-03-14T22:54:19.838973658Z < Cache-Control: no-cache couchbase-d96eed5d-1 | 2016-03-14T22:54:19.838984780Z < 100 36 0 0 100 36 0 5643 --:--:-- --:--:-- --:--:-- 6000 couchbase-d96eed5d-1 | 2016-03-14T22:54:19.839338450Z * Connection #0 to host 127.0.0.1 left intact couchbase-d96eed5d-1 | 2016-03-14T22:54:19.843462008Z * Trying 127.0.0.1... couchbase-d96eed5d-1 | 2016-03-14T22:54:19.844335715Z % Total % Received % Xferd Average Speed Time Time Time Current couchbase-d96eed5d-1 | 2016-03-14T22:54:19.845478686Z Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to 127.0.0.1 (127.0.0.1) port 8091 (#0) couchbase-d96eed5d-1 | 2016-03-14T22:54:19.845676061Z > POST /node/controller/setupServices HTTP/1.1 couchbase-d96eed5d-1 | 2016-03-14T22:54:19.845729619Z > User-Agent: curl/7.40.0-DEV couchbase-d96eed5d-1 | 2016-03-14T22:54:19.845805193Z > Host: 127.0.0.1:8091 couchbase-d96eed5d-1 | 2016-03-14T22:54:19.845858410Z > Accept: */* couchbase-d96eed5d-1 | 2016-03-14T22:54:19.845911479Z > Content-Length: 26 couchbase-d96eed5d-1 | 2016-03-14T22:54:19.845986653Z > Content-Type: application/x-www-form-urlencoded couchbase-d96eed5d-1 | 2016-03-14T22:54:19.846040578Z > couchbase-d96eed5d-1 | 2016-03-14T22:54:19.846312512Z } [26 bytes data] couchbase-d96eed5d-1 | 2016-03-14T22:54:19.846561659Z * upload completely sent off: 26 out of 26 bytes couchbase-d96eed5d-1 | 2016-03-14T22:54:19.847024846Z < HTTP/1.1 200 OK couchbase-d96eed5d-1 | 2016-03-14T22:54:19.847082032Z < Server: Couchbase Server couchbase-d96eed5d-1 | 2016-03-14T22:54:19.847157246Z < Pragma: no-cache couchbase-d96eed5d-1 | 2016-03-14T22:54:19.847211690Z < Date: Mon, 14 Mar 2016 22:54:19 GMT couchbase-d96eed5d-1 | 2016-03-14T22:54:19.847266024Z < Content-Length: 0 couchbase-d96eed5d-1 | 2016-03-14T22:54:19.847344403Z < Cache-Control: no-cache couchbase-d96eed5d-1 | 2016-03-14T22:54:19.847411160Z < 100 26 0 0 100 26 0 6056 --:--:-- --:--:-- --:--:-- 8666 couchbase-d96eed5d-1 | 2016-03-14T22:54:19.849284426Z * Connection #0 to host 127.0.0.1 left intact couchbase-d96eed5d-1 | 2016-03-14T22:54:19.853702443Z * Trying 127.0.0.1... couchbase-d96eed5d-1 | 2016-03-14T22:54:19.853890120Z % Total % Received % Xferd Average Speed Time Time Time Current couchbase-d96eed5d-1 | 2016-03-14T22:54:19.853943309Z Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to 127.0.0.1 (127.0.0.1) port 8091 (#0) couchbase-d96eed5d-1 | 2016-03-14T22:54:19.854112174Z > POST /settings/web HTTP/1.1 couchbase-d96eed5d-1 | 2016-03-14T22:54:19.854169870Z > User-Agent: curl/7.40.0-DEV couchbase-d96eed5d-1 | 2016-03-14T22:54:19.854223412Z > Host: 127.0.0.1:8091 couchbase-d96eed5d-1 | 2016-03-14T22:54:19.854278756Z > Accept: */* couchbase-d96eed5d-1 | 2016-03-14T22:54:19.854335649Z > Content-Length: 50 couchbase-d96eed5d-1 | 2016-03-14T22:54:19.854391073Z > Content-Type: application/x-www-form-urlencoded couchbase-d96eed5d-1 | 2016-03-14T22:54:19.854447141Z > couchbase-d96eed5d-1 | 2016-03-14T22:54:19.854683623Z } [50 bytes data] couchbase-d96eed5d-1 | 2016-03-14T22:54:19.855024680Z * upload completely sent off: 50 out of 50 bytes couchbase-d96eed5d-1 | 2016-03-14T22:54:19.859378932Z < HTTP/1.1 200 OK couchbase-d96eed5d-1 | 2016-03-14T22:54:19.859530830Z < Server: Couchbase Server couchbase-d96eed5d-1 | 2016-03-14T22:54:19.859611527Z < Pragma: no-cache couchbase-d96eed5d-1 | 2016-03-14T22:54:19.859794083Z < Date: Mon, 14 Mar 2016 22:54:19 GMT couchbase-d96eed5d-1 | 2016-03-14T22:54:19.859848224Z < Content-Type: application/json couchbase-d96eed5d-1 | 2016-03-14T22:54:19.859912932Z < Content-Length: 39 couchbase-d96eed5d-1 | 2016-03-14T22:54:19.859957829Z < Cache-Control: no-cache couchbase-d96eed5d-1 | 2016-03-14T22:54:19.859972017Z < couchbase-d96eed5d-1 | 2016-03-14T22:54:19.859986584Z { [39 bytes data] 100 89 100 39 100 50 6060 7770 --:--:-- --:--:-- --:--:-- 8333 couchbase-d96eed5d-1 | 2016-03-14T22:54:19.860221103Z * Connection #0 to host 127.0.0.1 left intact couchbase-d96eed5d-1 | 2016-03-14T22:54:19.860730000Z {"newBaseUri":"http://127.0.0.1:8091/"}/entrypoint.sh couchbase-server
日志的输出结果来自被回调以配置Couchbase服务器的Couchbase REST API。
在Docker Cloud内访问Couchbase Server
检查Docker Cloud服务以获取公开的容器端口:
docker-cloud service inspect 834343fd-b1d5-4d66-a2cd-69d27a471658 | jq ".container_ports" [ { "protocol": "tcp", "outer_port": 8091, "inner_port": 8091, "port_name": "unknown", "published": true, "endpoint_uri": "tcp://couchbase-d96eed5d.834343fd.svc.dockerapp.io:8091/" }, { "protocol": "tcp", "outer_port": 8092, "inner_port": 8092, "port_name": "unknown", "published": true, "endpoint_uri": "tcp://couchbase-d96eed5d.834343fd.svc.dockerapp.io:8092/" }, { "protocol": "tcp", "outer_port": 8093, "inner_port": 8093, "port_name": "unknown", "published": true, "endpoint_uri": "tcp://couchbase-d96eed5d.834343fd.svc.dockerapp.io:8093/" }, { "protocol": "tcp", "outer_port": 11210, "inner_port": 11210, "port_name": "unknown", "published": true, "endpoint_uri": "tcp://couchbase-d96eed5d.834343fd.svc.dockerapp.io:11210/" } ]
更具体地讲,Couchbase Web Console的URI可整理为:
docker-cloud service inspect 834343fd-b1d5-4d66-a2cd-69d27a471658 | jq ".container_ports[0].endpoint_uri" | sed 's/tcp/http/g' "http://couchbase-d96eed5d.834343fd.svc.dockerapp.io:8091/"
利用http://couchbase-d96eed5d.834343fd.svc.dockerapp.io:8091/访问Couchbase Web Console即可查看其登录界面。输入 Administrator与password。
Couchbase Web Console如下所示:
终止Docker Cloud服务与节点
检查当前正在运行的各Docker Cloud服务:
docker-cloud service ps NAME UUID STATUS #CONTAINERS IMAGE DEPLOYED PUBLIC DNS STACK couchbase-d96eed5d 834343fd ▶ Running 1 arungupta/couchbase:latest 26 minutes ago couchbase-d96eed5d.834343fd.svc.dockerapp.io
终止该服务:
docker-cloud service terminate couchbase-d96eed5d 834343fd-b1d5-4d66-a2cd-69d27a471658
检查节点列表:
docker-cloud node ls UUID FQDN LASTSEEN STATUS CLUSTER DOCKER_VER a8059155 a8059155-390c-42db-9fb1-3b1bd3fb222c.node.dockerapp.io 1 minute ago ▶ Deployed couchbase-node 1.9.1-cs2
终止该节点:
docker-cloud node rm a8059155 a8059155-390c-42db-9fb1-3b1bd3fb222c
原文标题: Couchbase Server: Getting Started With Docker Cloud
【51CTO.com独家译稿,合作站点转载请注明来源】