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

相关文章
相关标签/搜索