开发者社区> 问答> 正文

Swarm mode 集群服务编排的概述


容器服务支持 Docker Compose 编排模板来描述多容器应用。
编排模板允许您描述一个完整的应用,该应用可以由许多个服务组成。例如:一个门户网站应用,由一个 Nginx 服务、一个 Web 服务和一个数据库服务组成。
一个服务可能会有多个容器实例,所有容器实例的配置保持一致。例如:上述应用中的 Web 服务,就可以根据访问量需要启动两个甚至更多的容器。

能力


容器服务支持通过编排模板文件,自动化地部署和管理一个容器应用。
swarm mode 集群支持 Compose V1/V2 以及 Compose V3 版本的模板格式。更多详细信息,参见 Compose V1Compose V2Compose V3
容器服务在社区 Compose 模板描述的基础上提供了一系列扩展来简化 Web、微服务应用的部署和运维。更多详细信息,参见 标签说明

示例


下面是一个 WordPress 应用,包含了由 WordPress 镜像提供的 Web 服务和 MySQL 镜像提供的 db 服务。

Compose V1/V2 模板示例

  1. [backcolor=transparent]web[backcolor=transparent]:
  2. [backcolor=transparent]  image[backcolor=transparent]:[backcolor=transparent] wordpress[backcolor=transparent]:[backcolor=transparent]4.2
  3. [backcolor=transparent]  ports[backcolor=transparent]:
  4. [backcolor=transparent]    [backcolor=transparent]-[backcolor=transparent] [backcolor=transparent]"80"
  5. [backcolor=transparent]  environment[backcolor=transparent]:
  6. [backcolor=transparent]    [backcolor=transparent]-[backcolor=transparent] WORDPRESS_AUTH_KEY[backcolor=transparent]=[backcolor=transparent]changeme
  7. [backcolor=transparent]    [backcolor=transparent]-[backcolor=transparent] WORDPRESS_SECURE_AUTH_KEY[backcolor=transparent]=[backcolor=transparent]changeme
  8. [backcolor=transparent]    [backcolor=transparent]-[backcolor=transparent] WORDPRESS_LOGGED_IN_KEY[backcolor=transparent]=[backcolor=transparent]changeme
  9. [backcolor=transparent]    [backcolor=transparent]-[backcolor=transparent] WORDPRESS_NONCE_KEY[backcolor=transparent]=[backcolor=transparent]changeme
  10. [backcolor=transparent]    [backcolor=transparent]-[backcolor=transparent] WORDPRESS_AUTH_SALT[backcolor=transparent]=[backcolor=transparent]changeme
  11. [backcolor=transparent]    [backcolor=transparent]-[backcolor=transparent] WORDPRESS_SECURE_AUTH_SALT[backcolor=transparent]=[backcolor=transparent]changeme
  12. [backcolor=transparent]    [backcolor=transparent]-[backcolor=transparent] WORDPRESS_LOGGED_IN_SALT[backcolor=transparent]=[backcolor=transparent]changeme
  13. [backcolor=transparent]    [backcolor=transparent]-[backcolor=transparent] WORDPRESS_NONCE_SALT[backcolor=transparent]=[backcolor=transparent]changeme
  14. [backcolor=transparent]  restart[backcolor=transparent]:[backcolor=transparent] always
  15. [backcolor=transparent]  links[backcolor=transparent]:
  16. [backcolor=transparent]    [backcolor=transparent]-[backcolor=transparent] db[backcolor=transparent]:[backcolor=transparent]mysql
  17. [backcolor=transparent]  labels[backcolor=transparent]:[backcolor=transparent]
  18. [backcolor=transparent]    aliyun[backcolor=transparent].[backcolor=transparent]log_store_wordpress[backcolor=transparent]:[backcolor=transparent] stdout
  19. [backcolor=transparent]    aliyun[backcolor=transparent].[backcolor=transparent]probe[backcolor=transparent].[backcolor=transparent]url[backcolor=transparent]:[backcolor=transparent] http[backcolor=transparent]:[backcolor=transparent]//container/license.txt
  20. [backcolor=transparent]    aliyun[backcolor=transparent].[backcolor=transparent]probe[backcolor=transparent].[backcolor=transparent]initial_delay_seconds[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]"10"
  21. [backcolor=transparent]    aliyun[backcolor=transparent].[backcolor=transparent]routing[backcolor=transparent].[backcolor=transparent]port_80[backcolor=transparent]:[backcolor=transparent] wordpress[backcolor=transparent];[backcolor=transparent]http[backcolor=transparent]:[backcolor=transparent]//www.example.com;https://www.nice.com
  22. [backcolor=transparent]    aliyun[backcolor=transparent].[backcolor=transparent]scale[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]"3"
  23. [backcolor=transparent]db[backcolor=transparent]:
  24. [backcolor=transparent]  image[backcolor=transparent]:[backcolor=transparent] mysql[backcolor=transparent]:[backcolor=transparent]5.6
  25. [backcolor=transparent]  environment[backcolor=transparent]:
  26. [backcolor=transparent]    MYSQL_ROOT_PASSWORD[backcolor=transparent]:[backcolor=transparent] password
  27. [backcolor=transparent]  restart[backcolor=transparent]:[backcolor=transparent] always
  28. [backcolor=transparent]  labels[backcolor=transparent]:[backcolor=transparent]
  29. [backcolor=transparent]    aliyun[backcolor=transparent].[backcolor=transparent]log_store_mysql[backcolor=transparent]:[backcolor=transparent] stdout


Compose V3 模板示例

  1. [backcolor=transparent]version[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]'3'
  2. [backcolor=transparent]services[backcolor=transparent]:
  3. [backcolor=transparent]  web[backcolor=transparent]:
  4. [backcolor=transparent]    image[backcolor=transparent]:[backcolor=transparent] wordpress[backcolor=transparent]:[backcolor=transparent]4
  5. [backcolor=transparent]    environment[backcolor=transparent]:
  6. [backcolor=transparent]      [backcolor=transparent]-[backcolor=transparent] WORDPRESS_DB_PASSWORD[backcolor=transparent]=[backcolor=transparent]password
  7. [backcolor=transparent]      [backcolor=transparent]-[backcolor=transparent] WORDPRESS_AUTH_KEY[backcolor=transparent]=[backcolor=transparent]changeme
  8. [backcolor=transparent]      [backcolor=transparent]-[backcolor=transparent] WORDPRESS_SECURE_AUTH_KEY[backcolor=transparent]=[backcolor=transparent]changeme
  9. [backcolor=transparent]      [backcolor=transparent]-[backcolor=transparent] WORDPRESS_LOGGED_IN_KEY[backcolor=transparent]=[backcolor=transparent]changeme
  10. [backcolor=transparent]      [backcolor=transparent]-[backcolor=transparent] WORDPRESS_NONCE_KEY[backcolor=transparent]=[backcolor=transparent]changeme
  11. [backcolor=transparent]      [backcolor=transparent]-[backcolor=transparent] WORDPRESS_AUTH_SALT[backcolor=transparent]=[backcolor=transparent]changeme
  12. [backcolor=transparent]      [backcolor=transparent]-[backcolor=transparent] WORDPRESS_SECURE_AUTH_SALT[backcolor=transparent]=[backcolor=transparent]changeme
  13. [backcolor=transparent]      [backcolor=transparent]-[backcolor=transparent] WORDPRESS_LOGGED_IN_SALT[backcolor=transparent]=[backcolor=transparent]changeme
  14. [backcolor=transparent]      [backcolor=transparent]-[backcolor=transparent] WORDPRESS_NONCE_SALT[backcolor=transparent]=[backcolor=transparent]changeme
  15. [backcolor=transparent]      [backcolor=transparent]-[backcolor=transparent] WORDPRESS_NONCE_AA[backcolor=transparent]=[backcolor=transparent]changeme
  16. [backcolor=transparent]    ports[backcolor=transparent]:
  17. [backcolor=transparent]      [backcolor=transparent]-[backcolor=transparent] [backcolor=transparent]80
  18. [backcolor=transparent]    depends_on[backcolor=transparent]:
  19. [backcolor=transparent]      [backcolor=transparent]-[backcolor=transparent] mysql
  20. [backcolor=transparent]    deploy[backcolor=transparent]:
  21. [backcolor=transparent]      replicas[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]3
  22. [backcolor=transparent]      restart_policy[backcolor=transparent]:
  23. [backcolor=transparent]        condition[backcolor=transparent]:[backcolor=transparent] on[backcolor=transparent]-[backcolor=transparent]failure
  24. [backcolor=transparent]    labels[backcolor=transparent]:
  25. [backcolor=transparent]      aliyun[backcolor=transparent].[backcolor=transparent]routing[backcolor=transparent].[backcolor=transparent]port_80[backcolor=transparent]:[backcolor=transparent] wordpress
  26. [backcolor=transparent]  mysql[backcolor=transparent]:
  27. [backcolor=transparent]    image[backcolor=transparent]:[backcolor=transparent] mysql[backcolor=transparent]:[backcolor=transparent]5.7
  28. [backcolor=transparent]    environment[backcolor=transparent]:
  29. [backcolor=transparent]      [backcolor=transparent]-[backcolor=transparent] MYSQL_ROOT_PASSWORD[backcolor=transparent]=[backcolor=transparent]password
  30. [backcolor=transparent]    deploy[backcolor=transparent]:
  31. [backcolor=transparent]      restart_policy[backcolor=transparent]:
  32. [backcolor=transparent]        condition[backcolor=transparent]:[backcolor=transparent] on[backcolor=transparent]-[backcolor=transparent]failure

展开
收起
反向一觉 2017-10-30 15:04:54 2167 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
GitOps:Kubernetes多集群环境下的高效CICD实践 立即下载
基于Kubernetes实现弹性的CI/CD系统 立即下载
多租户Kubernetes实践-从容器运行时到SDN 立即下载