容器服务支持
Docker Compose 编排模板来描述多容器应用。
编排模板允许您描述一个完整的应用,该应用可以由许多个服务组成。例如:一个门户网站应用,由一个 Nginx 服务、一个 Web 服务和一个数据库服务组成。
一个服务可能会有多个容器实例,所有容器实例的配置保持一致。例如:上述应用中的 Web 服务,就可以根据访问量需要启动两个甚至更多的容器。
能力
容器服务支持通过编排模板文件,自动化地部署和管理一个容器应用。
swarm mode 集群支持 Compose V1/V2 以及 Compose V3 版本的模板格式。更多详细信息,参见
Compose V1、
Compose V2 和
Compose V3。
容器服务在社区 Compose 模板描述的基础上提供了一系列扩展来简化 Web、微服务应用的部署和运维。更多详细信息,参见
标签说明。
示例
下面是一个 WordPress 应用,包含了由 WordPress 镜像提供的 Web 服务和 MySQL 镜像提供的 db 服务。
Compose V1/V2 模板示例
- [backcolor=transparent]web[backcolor=transparent]:
- [backcolor=transparent] image[backcolor=transparent]:[backcolor=transparent] wordpress[backcolor=transparent]:[backcolor=transparent]4.2
- [backcolor=transparent] ports[backcolor=transparent]:
- [backcolor=transparent] [backcolor=transparent]-[backcolor=transparent] [backcolor=transparent]"80"
- [backcolor=transparent] environment[backcolor=transparent]:
- [backcolor=transparent] [backcolor=transparent]-[backcolor=transparent] WORDPRESS_AUTH_KEY[backcolor=transparent]=[backcolor=transparent]changeme
- [backcolor=transparent] [backcolor=transparent]-[backcolor=transparent] WORDPRESS_SECURE_AUTH_KEY[backcolor=transparent]=[backcolor=transparent]changeme
- [backcolor=transparent] [backcolor=transparent]-[backcolor=transparent] WORDPRESS_LOGGED_IN_KEY[backcolor=transparent]=[backcolor=transparent]changeme
- [backcolor=transparent] [backcolor=transparent]-[backcolor=transparent] WORDPRESS_NONCE_KEY[backcolor=transparent]=[backcolor=transparent]changeme
- [backcolor=transparent] [backcolor=transparent]-[backcolor=transparent] WORDPRESS_AUTH_SALT[backcolor=transparent]=[backcolor=transparent]changeme
- [backcolor=transparent] [backcolor=transparent]-[backcolor=transparent] WORDPRESS_SECURE_AUTH_SALT[backcolor=transparent]=[backcolor=transparent]changeme
- [backcolor=transparent] [backcolor=transparent]-[backcolor=transparent] WORDPRESS_LOGGED_IN_SALT[backcolor=transparent]=[backcolor=transparent]changeme
- [backcolor=transparent] [backcolor=transparent]-[backcolor=transparent] WORDPRESS_NONCE_SALT[backcolor=transparent]=[backcolor=transparent]changeme
- [backcolor=transparent] restart[backcolor=transparent]:[backcolor=transparent] always
- [backcolor=transparent] links[backcolor=transparent]:
- [backcolor=transparent] [backcolor=transparent]-[backcolor=transparent] db[backcolor=transparent]:[backcolor=transparent]mysql
- [backcolor=transparent] labels[backcolor=transparent]:[backcolor=transparent]
- [backcolor=transparent] aliyun[backcolor=transparent].[backcolor=transparent]log_store_wordpress[backcolor=transparent]:[backcolor=transparent] stdout
- [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
- [backcolor=transparent] aliyun[backcolor=transparent].[backcolor=transparent]probe[backcolor=transparent].[backcolor=transparent]initial_delay_seconds[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]"10"
- [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
- [backcolor=transparent] aliyun[backcolor=transparent].[backcolor=transparent]scale[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]"3"
- [backcolor=transparent]db[backcolor=transparent]:
- [backcolor=transparent] image[backcolor=transparent]:[backcolor=transparent] mysql[backcolor=transparent]:[backcolor=transparent]5.6
- [backcolor=transparent] environment[backcolor=transparent]:
- [backcolor=transparent] MYSQL_ROOT_PASSWORD[backcolor=transparent]:[backcolor=transparent] password
- [backcolor=transparent] restart[backcolor=transparent]:[backcolor=transparent] always
- [backcolor=transparent] labels[backcolor=transparent]:[backcolor=transparent]
- [backcolor=transparent] aliyun[backcolor=transparent].[backcolor=transparent]log_store_mysql[backcolor=transparent]:[backcolor=transparent] stdout
Compose V3 模板示例
- [backcolor=transparent]version[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]'3'
- [backcolor=transparent]services[backcolor=transparent]:
- [backcolor=transparent] web[backcolor=transparent]:
- [backcolor=transparent] image[backcolor=transparent]:[backcolor=transparent] wordpress[backcolor=transparent]:[backcolor=transparent]4
- [backcolor=transparent] environment[backcolor=transparent]:
- [backcolor=transparent] [backcolor=transparent]-[backcolor=transparent] WORDPRESS_DB_PASSWORD[backcolor=transparent]=[backcolor=transparent]password
- [backcolor=transparent] [backcolor=transparent]-[backcolor=transparent] WORDPRESS_AUTH_KEY[backcolor=transparent]=[backcolor=transparent]changeme
- [backcolor=transparent] [backcolor=transparent]-[backcolor=transparent] WORDPRESS_SECURE_AUTH_KEY[backcolor=transparent]=[backcolor=transparent]changeme
- [backcolor=transparent] [backcolor=transparent]-[backcolor=transparent] WORDPRESS_LOGGED_IN_KEY[backcolor=transparent]=[backcolor=transparent]changeme
- [backcolor=transparent] [backcolor=transparent]-[backcolor=transparent] WORDPRESS_NONCE_KEY[backcolor=transparent]=[backcolor=transparent]changeme
- [backcolor=transparent] [backcolor=transparent]-[backcolor=transparent] WORDPRESS_AUTH_SALT[backcolor=transparent]=[backcolor=transparent]changeme
- [backcolor=transparent] [backcolor=transparent]-[backcolor=transparent] WORDPRESS_SECURE_AUTH_SALT[backcolor=transparent]=[backcolor=transparent]changeme
- [backcolor=transparent] [backcolor=transparent]-[backcolor=transparent] WORDPRESS_LOGGED_IN_SALT[backcolor=transparent]=[backcolor=transparent]changeme
- [backcolor=transparent] [backcolor=transparent]-[backcolor=transparent] WORDPRESS_NONCE_SALT[backcolor=transparent]=[backcolor=transparent]changeme
- [backcolor=transparent] [backcolor=transparent]-[backcolor=transparent] WORDPRESS_NONCE_AA[backcolor=transparent]=[backcolor=transparent]changeme
- [backcolor=transparent] ports[backcolor=transparent]:
- [backcolor=transparent] [backcolor=transparent]-[backcolor=transparent] [backcolor=transparent]80
- [backcolor=transparent] depends_on[backcolor=transparent]:
- [backcolor=transparent] [backcolor=transparent]-[backcolor=transparent] mysql
- [backcolor=transparent] deploy[backcolor=transparent]:
- [backcolor=transparent] replicas[backcolor=transparent]:[backcolor=transparent] [backcolor=transparent]3
- [backcolor=transparent] restart_policy[backcolor=transparent]:
- [backcolor=transparent] condition[backcolor=transparent]:[backcolor=transparent] on[backcolor=transparent]-[backcolor=transparent]failure
- [backcolor=transparent] labels[backcolor=transparent]:
- [backcolor=transparent] aliyun[backcolor=transparent].[backcolor=transparent]routing[backcolor=transparent].[backcolor=transparent]port_80[backcolor=transparent]:[backcolor=transparent] wordpress
- [backcolor=transparent] mysql[backcolor=transparent]:
- [backcolor=transparent] image[backcolor=transparent]:[backcolor=transparent] mysql[backcolor=transparent]:[backcolor=transparent]5.7
- [backcolor=transparent] environment[backcolor=transparent]:
- [backcolor=transparent] [backcolor=transparent]-[backcolor=transparent] MYSQL_ROOT_PASSWORD[backcolor=transparent]=[backcolor=transparent]password
- [backcolor=transparent] deploy[backcolor=transparent]:
- [backcolor=transparent] restart_policy[backcolor=transparent]:
- [backcolor=transparent] condition[backcolor=transparent]:[backcolor=transparent] on[backcolor=transparent]-[backcolor=transparent]failure