1. version: "3"
    2. services:
    3. redis:
    4. image: redis:alpine
    5. ports:
    6. - "6379"
    7. networks:
    8. - frontend
    9. deploy:
    10. replicas: 2
    11. update_config:
    12. parallelism: 2
    13. delay: 10s
    14. restart_policy:
    15. condition: on-failure
    16. db:
    17. image: postgres:9.4
    18. volumes:
    19. - db-data:/var/lib/postgresql/data
    20. networks:
    21. - backend
    22. deploy:
    23. placement:
    24. constraints: [node.role == manager]
    25. vote:
    26. image: dockersamples/examplevotingapp_vote:before
    27. ports:
    28. - 5000:80
    29. networks:
    30. - frontend
    31. depends_on:
    32. - redis
    33. deploy:
    34. replicas: 2
    35. update_config:
    36. parallelism: 2
    37. restart_policy:
    38. condition: on-failure
    39. result:
    40. image: dockersamples/examplevotingapp_result:before
    41. ports:
    42. - 5001:80
    43. networks:
    44. - backend
    45. depends_on:
    46. - db
    47. deploy:
    48. replicas: 1
    49. update_config:
    50. parallelism: 2
    51. delay: 10s
    52. restart_policy:
    53. condition: on-failure
    54. worker:
    55. image: dockersamples/examplevotingapp_worker
    56. networks:
    57. - frontend
    58. - backend
    59. deploy:
    60. mode: replicated
    61. replicas: 1
    62. labels: [APP=VOTING]
    63. restart_policy:
    64. condition: on-failure
    65. delay: 10s
    66. max_attempts: 3
    67. window: 120s
    68. placement:
    69. constraints: [node.role == manager]
    70. visualizer:
    71. image: dockersamples/visualizer:stable
    72. ports:
    73. - "8080:8080"
    74. stop_grace_period: 1m30s
    75. volumes:
    76. - "/var/run/docker.sock:/var/run/docker.sock"
    77. deploy:
    78. placement:
    79. constraints: [node.role == manager]
    80. networks:
    81. frontend:
    82. backend:
    83. volumes:
    84. db-data:

    新增并启动 example
    docker stack deploy example —compose-file=docker-compose.yml

    image.png

    查看 example services详情
    docker stack ps example
    image.png

    查看 example services信息
    docker stack services example
    image.png

    投票:http://10.211.55.6:5000/
    结果:http://10.211.55.6:5001/
    services可视化分析:http://10.211.55.6:8080/