『中级篇』Docker-Stack部署投票应用(50)

之前用docker-compose创建过投票应用,现在通过docker-stack来创建多机的部署。源码:https://github.com/limingios/docker/tree/master/No.5/labs/wordpress

######docker-compose文件

编辑docker-compose文件,从github下载下来。
这个配置文件里面装了一个可视化的配置工具visualizer:stable 可以查看到docker-swarm 所有的节点信息。

cd labs/
cd example-vote-app/
more docker-compose.yml 
````

* compose的语法

![](https://upload-images.jianshu.io/upload_images/11223715-b0a26053d53c068f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

``` bash
version: "3"
services:

  redis:
    image: redis:alpine
    ports:
      - "6379"
    networks:
      - frontend
    deploy:
      replicas: 2
      update_config:
        parallelism: 2
        delay: 10s
      restart_policy:
        condition: on-failure

  db:
    image: postgres:9.4
    volumes:
      - db-data:/var/lib/postgresql/data
    networks:
      - backend
    deploy:
      placement:
        constraints: [node.role == manager]

  vote:
    image: dockersamples/examplevotingapp_vote:before
    ports:
      - 5000:80
    networks:
      - frontend
    depends_on:
      - redis
    deploy:
      replicas: 2
      update_config:
        parallelism: 2
      restart_policy:
        condition: on-failure

  result:
    image: dockersamples/examplevotingapp_result:before
    ports:
      - 5001:80
    networks:
      - backend
    depends_on:
      - db
    deploy:
      replicas: 1
      update_config:
        parallelism: 2
        delay: 10s
      restart_policy:
        condition: on-failure

  worker:
    image: dockersamples/examplevotingapp_worker
    networks:
      - frontend
      - backend
    deploy:
      mode: replicated
      replicas: 1
      labels: [APP=VOTING]
      restart_policy:
        condition: on-failure
        delay: 10s
        max_attempts: 3
        window: 120s
      placement:
        constraints: [node.role == manager]

  visualizer:
    image: dockersamples/visualizer:stable
    ports:
      - "8080:8080"
    stop_grace_period: 1m30s
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
    deploy:
      placement:
        constraints: [node.role == manager]

networks:
  frontend:
  backend:

volumes:
  db-data:

投票docker-stack 部署
docker stack deploy example --compose-file=docker-compose.yml
docker stack ls
docker stack services example



  • 打开网页
    http://172.28.128.3:5000/
    http://172.28.128.3:5001/
    http://172.28.128.3:8080/


  • 扩展vote
docker service scale example_vote=4

  • 删除stack
docker stack rm example

PS:docker stack 就介绍到这里吧,其实最关键的是编写docker-compose.yml查看官网的学习方式。对于本次编写的一些关键字建议看看官网学习下。

>>原创文章,欢迎转载。转载请注明:转载自IT人故事会,谢谢!
>>原文链接地址:『中级篇』Docker-Stack部署投票应用(50)
上一篇: 下一篇:

发表评论

电子邮件地址不会被公开。 必填项已用*标注