源码 https://github.com/dockersamples/example-voting-app

    1. version: "3"
    2. services:
    3. redis:
    4. image: redis:alpine
    5. networks:
    6. - frontend
    7. deploy: # 设置
    8. replicas: 1 # 设置 replicas 服务的个数
    9. update_config: # 更新的配置
    10. parallelism: 2 # 调度程序同时更新的最大服务任务数
    11. delay: 10s # 标志配置更新服务任务或任务集之间的时间延迟
    12. restart_policy:
    13. condition: on-failure
    14. db:
    15. image: postgres:9.4
    16. environment:
    17. POSTGRES_USER: "postgres"
    18. POSTGRES_PASSWORD: "postgres"
    19. volumes:
    20. - db-data:/var/lib/postgresql/data
    21. networks:
    22. - backend
    23. deploy:
    24. placement:
    25. constraints: [node.role == manager] # 指定 db 只能部署在 manager 节点上
    26. vote:
    27. image: dockersamples/examplevotingapp_vote:before
    28. ports:
    29. - 5000:80
    30. networks:
    31. - frontend
    32. depends_on:
    33. - redis
    34. deploy:
    35. replicas: 2
    36. update_config:
    37. parallelism: 2
    38. restart_policy:
    39. condition: on-failure
    40. result:
    41. image: dockersamples/examplevotingapp_result:before
    42. ports:
    43. - 5001:80
    44. networks:
    45. - backend
    46. depends_on:
    47. - db
    48. deploy:
    49. replicas: 1
    50. update_config:
    51. parallelism: 2
    52. delay: 10s
    53. restart_policy:
    54. condition: on-failure
    55. worker:
    56. image: dockersamples/examplevotingapp_worker
    57. networks:
    58. - frontend
    59. - backend
    60. depends_on:
    61. - db
    62. - redis
    63. deploy:
    64. mode: replicated
    65. replicas: 1
    66. labels: [APP=VOTING]
    67. restart_policy:
    68. condition: on-failure
    69. delay: 10s
    70. max_attempts: 3
    71. window: 120s
    72. placement:
    73. constraints: [node.role == manager]
    74. visualizer:
    75. image: dockersamples/visualizer:stable
    76. ports:
    77. - "8080:8080"
    78. stop_grace_period: 1m30s
    79. volumes:
    80. - "/var/run/docker.sock:/var/run/docker.sock"
    81. deploy:
    82. placement:
    83. constraints: [node.role == manager]
    84. networks:
    85. frontend:
    86. backend:
    87. volumes:
    88. db-data: