標籤:

Docker1.12 Swarm中容器互聯&數據卷掛載

一,數據卷

創建volume:

docker volume create redisn

查看信息:

root@dc-0:~# docker volume inspect redisn[n {n "Name": "redis",n "Driver": "local",n "Mountpoint": "/var/lib/docker/volumes/redis/_data",n "Labels": {},n "Scope": "local"n }n]n

掛載dir:

--mount type=bind,source=/data,target=/data,readonly=false n--mount type=bind,source=/data,target=/data,readonly=truen

掛載volume:

--mount type=volume,source=redis,target=/var/lib/mysql,readonly=false nn--mount type=volume,source=redis,target=/etc/localtime,readonly=truen

二,容器互聯(overlay)

創建網路(overlay):

docker network create -d overlay dnetn

網路信息:

root@dc-0:~# docker network inspect dnetn[n {n "Name": "dnet",n "Id": "4c2x9r76vyd0ok74tq432xcd4",n "Scope": "swarm",n "Driver": "overlay",n "EnableIPv6": false,n "IPAM": {n "Driver": "default",n "Options": null,n "Config": [n {n "Subnet": "10.0.0.0/24",n "Gateway": "10.0.0.1"n }n ]n },n "Internal": false,n "Containers": {n "70284bf80680734946fbca022b7577291bf1ef71173e853a7a7a6cf8858b2638": {n "Name": "redis.1.eacxayx98j1l9zi27orsees7d",n "EndpointID": "1eefaa5b6bcfaf06d365b75c3b8364778d2c7684430044e812a0d267e9c3f096",n "MacAddress": "02:42:0a:00:00:03",n "IPv4Address": "10.0.0.3/24",n "IPv6Address": ""n }n },n "Options": {n "com.docker.network.driver.overlay.vxlanid_list": "257"n },n "Labels": {}n }n]n

創建服務:

# Redisndocker service create n--name redis -p 6379:6379 n--mount type=volume,source=redis,target=/data,readonly=false n--network dnet nredis:3.2-alpine nredis-server --appendonly yes --requirepass passwordnn# Testndocker service create --name test --network dnet redis:3.2-alpinen

服務測試:

# 在redis中ping 測試服務testndocker exec -it 70284bf80680 /bin/shnn/data # ping testnPING test (10.0.0.4): 56 data bytesn64 bytes from 10.0.0.4: seq=0 ttl=64 time=0.124 msn64 bytes from 10.0.0.4: seq=1 ttl=64 time=0.109 msn64 bytes from 10.0.0.4: seq=2 ttl=64 time=0.108 msnn# 在test中ping 測試服務redisn/data # ping redisnPING redis (10.0.0.2): 56 data bytesn64 bytes from 10.0.0.2: seq=0 ttl=64 time=0.042 msn64 bytes from 10.0.0.2: seq=1 ttl=64 time=0.108 msn

可以看到已經能夠相互連接了。

推薦閱讀:

docker怎麼修改拉取源從指定的國內倉庫拉取鏡像?
Egg.js+Antd 擼個簡易版阿里雲CS控制台?
【DockerCon2017最新技術解讀】Docker最新特性介紹
在雲環境中的應用部署方式上,Docker會不會取代KVM、Xen之類的虛擬機技術?

TAG:Docker |