docker Swarm,docker stack

docker使用自有集群Swarm使用场景较少,这里写个简单的示例,集群推荐使用kubernetes,docker在未来将原生支持kubernetes

  • 启用Swarm
  docker swarm init --advertise-addr 192.168.99.100
  • 加入一个工作节点
  docker swarm join \
      --token SWMTKN-1-22qet9fb8lhgmfj06dbz9pf6ed0g6y1hmug24xb9iosevpfgws-e3hfqm8e0lm73vnw83nxq720d \
      192.168.99.100:2377
  • 生成Token
  docker swarm join-token manager
  • 加入一个Manager节点
  docker swarm join \
    --token SWMTKN-1-22qet9fb8lhgmfj06dbz9pf6ed0g6y1hmug24xb9iosevpfgws-bl2esy7m2h9uwgl8xsyhhk96q \
    192.168.99.100:2377
  • 编写stack.yml文件

    version: '3.1'
    services:
    zoo1:
        image: zookeeper
        hostname: zoo1
        ports:
        - 2181:2181
        environment:
        ZOO_MY_ID: 1
        ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
    zoo2:
        image: zookeeper
        hostname: zoo2
        ports:
        - 2182:2181
        environment:
        ZOO_MY_ID: 2
        ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
    zoo3:
        image: zookeeper
        hostname: zoo3
        ports:
        - 2183:2181
        environment:
        ZOO_MY_ID: 3
        ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
    
  • 生成deploy

    docker stack deploy -c docker-cloud.yml zookeeper
    
  • 等待镜像拉好之后查看部署是否成功

VinkDong

open to open