docker_practice/swarm_mode/stack.md

99 lines
2.6 KiB
Go
Raw Normal View History

# Swarm 使 compose
2017-11-25 15:43:51 +08:00
2017-11-26 09:54:16 +08:00
使 `docker-compose.yml` `Swarm` 使 `compose` `docker-compose.yml`
2017-11-25 15:43:51 +08:00
使 `docker service create` 使 `docker-compose.yml`
`Swarm` `WordPress`
```yaml
version: "3"
services:
wordpress:
image: wordpress
ports:
- 80:80
networks:
- overlay
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
deploy:
mode: replicated
replicas: 3
db:
image: mysql
networks:
- overlay
volumes:
- db-data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
deploy:
placement:
constraints: [node.role == manager]
visualizer:
image: dockersamples/visualizer:stable
ports:
- "8080:8080"
stop_grace_period: 1m30s
volumes:
- "/var/run/docker.sock:/var/run/docker.sock"
deploy:
placement:
constraints: [node.role == manager]
volumes:
db-data:
networks:
overlay:
```
`Swarm` `visualizer`
`Swarm` 使 `docker-compose.yml` `docker stack`
##
2017-11-25 15:43:51 +08:00
2017-11-26 09:54:16 +08:00
使 `docker stack deploy` `-c` compose
2017-11-25 15:43:51 +08:00
```bash
$ docker stack deploy -c docker-compose.yml wordpress
```
`任一节点IP:8080`
![](image/wordpress.png)
`任一节点IP` `WordPress` `任一节点IP` `WordPress`
##
2017-11-25 15:43:51 +08:00
```bash
$ docker stack ls
NAME SERVICES
wordpress 3
```
##
2017-11-25 15:43:51 +08:00
使 `docker stack down`
```bash
$ docker stack down wordpress
Removing service wordpress_db
Removing service wordpress_visualizer
Removing service wordpress_wordpress
Removing network wordpress_overlay
Removing network wordpress_default
```
使 `数据卷`使 `docker volume rm`