docker-compose文件
编辑docker-compose文件,从github下载下来。
cd labs/cd wordpress/ more docker-compose.yml
compose的语法
version: '3'services: web: image: wordpress ports: - 8080:80 environment: WORDPRESS_DB_HOST: mysql WORDPRESS_DB_PASSWORD: root networks: - my-network depends_on: - mysql deploy: mode: replicated replicas: 3 restart_policy: condition: on-failure delay: 5s max_attempts: 3 update_config: parallelism: 1 delay: 10s mysql: image: mysql environment: MYSQL_ROOT_PASSWORD: root MYSQL_DATABASE: wordpress volumes: - mysql-data:/var/lib/mysql networks: - my-network deploy: mode: global placement: constraints: - node.role == manager volumes: mysql-data: networks: my-network: driver: overlay
docker-stack 部署
docker stack deploy 部署一个Compose模板到Docker集群中作为一个stack,相当于之前的docker-compose up
docker stack ls 列出目前的所有stack*
docker stack ps 展示一个stack中对应的容器,相当于之前的*
docker-compose ps
docker stack rm 删除一个stack以及它包含的服务和容器
docker stack services 展示stack下面对应的服务有了Docker stack的命令,我们就可以方便的把以前系统的Compose模板以内置编排Service的方式部署到现在的Docker集群中。
#了解docker stack基本命令docker stack
docker stack deploy wordpress --compose-file=docker-compose.yml docker stack ps wordpress docker stack services wordpress
PS:docker-stack 就是通过yml类似docker-compose的文件来进行多机的部署。
作者:IT人故事会
链接:https://www.jianshu.com/p/9660227ac3ea