docker三劍客docker-compose、docker-machine、swarm

docker-composenode

安裝compose
curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
測試安裝
$ docker-compose --version
linux

docker-compose version 1.21.2, build 1719cebgit

經常使用命令github

命令:
  build              Build or rebuild services
  bundle             Generate a Docker bundle from the Compose file
  config             Validate and view the Compose file
  create             Create services
  down               Stop and remove containers, networks, images, and volumes
  events             Receive real time events from containers
  exec               Execute a command in a running container
  help               Get help on a command
  images             List images
  kill               Kill containers
  logs               View output from containers
  pause              Pause services
  port               Print the public port for a port binding
  ps                 List containers
  pull               Pull service images
  push               Push service images
  restart            Restart services
  rm                 Remove stopped containers
  run                Run a one-off command
  scale              Set number of containers for a service
  start              Start services
  stop               Stop services
  top                Display the running processes
  unpause            Unpause services
  up                 Create and start containers
  version            Show the Docker-Compose version information
docker


https://docs.docker.com/compose/overview/負載均衡

https://blog.csdn.net/Dante_003/article/details/70160493
框架

docker-machinessh

簡介

docker-machine是安裝docker環境的一個工具,能夠在一臺機器上經過命令控制幾臺機器安裝docker環境,運行docker命令,建立docker swarm集羣的工具。
安裝
docker-machine和compose有點相似,都是一個可運行的linux二進制文件(下面都是基於linux版本作的),下載下來這個文件後放到/usr/local/bin裏面設置文件權限就能夠直接使用了,docker-machine的github地址
https://github.com/docker/machine

curl -L https://github.com/docker/machine/releases/download/v0.10.0/docker-machine-`uname -s`-`uname -m` >/tmp/docker-machine &&
    chmod +x /tmp/docker-machine &&
    sudo cp /tmp/docker-machine /usr/local/bin/docker-machine
使用
按照docker-machine github上的介紹,它是一個簡化Docker安裝的命令行工具,經過一個簡單的命令行便可在相應的平臺上安裝Docker,好比VirtualBox、 Digital Ocean、Microsoft Azure。根據他的描述和github上的例子能夠看出他能夠直接在指定平臺上建立機器。
咱們這裏只測試已經建立好有ip的實體機或者虛擬機。
docker-machine操做各個機器實際上用ssh無密碼訪問的,若是是在已經配置好ip的實體機或虛擬機上用就要手動或者使用腳本設置無密碼訪問了。

 無密碼訪問
ssh-keygen #一直回車
ssh-copy-id root@192.168.1.28 #ip爲docker-machine要操做的機器,輸入密碼
##上面結束以後,每臺機器上還得安裝net-tools,docker-machine會用到netstat命令來檢測端口使用狀況,若是機器上沒有安裝會報錯。若是你肯定那臺機器上的端口沒問題,即便報錯也沒問題,最終那臺機器仍是會加入到docker-machine的管理中。
yum install net-tools

    鏈接機器
docker-machine create -d generic --generic-ip-address=192.168.1.28 node28

node28爲給機器的別名
-d generic驅動類型
–generic-ip-address 要控制機器的ip,必須
–generic-engine-port docker-engine的遠程訪問端口,默認爲2376
–generic-ssh-key 遠程訪問機器的私鑰,默認使用.ssh/下面的私鑰
–generic-ssh-user 遠程訪問機器的用戶名,默認爲root
–generic-ssh-port 遠程ssh訪問的端口,默認爲22
–engine-insecure-registry docker-engine的insecure-registry
–engine-install-url 安裝docker-engine的地址,默認爲」https://get.docker.com」
–engine-registry-mirror docker-engine鏡像的代理地址
上面的命令根據國內環境能夠換爲下面

docker-machine create \
-d generic \
--generic-ip-address=192.168.1.28 \
--engine-install-url=https://get.daocloud.io/docker/   \
--engine-registry-mirror=http://91c0cc1e.m.daocloud.io  \
node28
經過docker-machine鏈接了各個機器後,就能夠經過docker-machine來操做各個機器了,更多命令查看 docker-machine –help
curl

https://docs.docker.com/machine/install-machine/工具

https://blog.csdn.net/vchy_zhao/article/details/70238472

swarm

簡介
swarm從docker1.9版本開始就有了,但功能不完善、性能不穩定,一直不能登入生產環境,從1.12版本內置到了docker-engine中,能夠直接使用docker swarm命令來操做swarm。
swarm是docker集羣的資源管理工具。簡單點理解,在不少臺機器上部署docker,組成一個docker集羣,並把整個集羣的資源抽象成資源池,使用者部署docker應用的時候,只須要將應用交給swarm,swarm會根據整個集羣資源的使用狀況來分配資源給部署的docker應用,能夠將這個集羣的資源利用率達到最大。
相似的服務框架還有mesos+marathon,kubernetes。
編者是從很早接觸docker的,swarm尚未出來,kubernetes還不成熟沒有人在生產環境使用。
①最先使用的是mesos+marathon那一套,優勢是基於成熟的資源調度管理框架mesos,缺點是部署起來仍是很麻煩的,像服務發現、負載均衡等概念在裏面也都有,但都是碎片化以插件的形式存在,整個體系感受不是很完善、不像一個總體。
②kubernetes從發佈1.0版本之後在生產獲得了不少實踐,開始步入主流壓過swarm和mesos+marathon,kubernetes針對docker應用集羣的特色,歸納出幾個對象,pod、service、replication controller,pod爲運行的基本單元,service則是專門來服務發現和服務代理的,replication controller 應用的副本作負載均衡。kubernetes就是一個很專業很全面完善的docker集羣管理工具。
③swarm在不少方面很像kubernetes,不知道是否是偷偷抄襲的。swarm經過命令就能夠很簡單的在docker集羣中建立應用設置副本數量,內置服務發現代理。swarm+compose≈kubernetes。swarm因爲如今內置於docker中,使用部署更簡單,功能上和kubernetes很類似,輕量級。
經常使用命令
    swarm init
    swarm join
    service create
    service inspect
    service ls
    service rm
    service scale
    service ps
    service update

https://docs.docker.com/engine/swarm/#feature-highlights

https://blog.csdn.net/Dante_003/article/details/70171804

相關文章
相關標籤/搜索