docker_practice/swarm_mode/stack.md

99 lines
2.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# Swarm 使 compose
使 `docker-compose.yml` `Swarm` 使 `compose` `docker-compose.yml`
使 `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`
##
使 `docker stack deploy` `-c` compose
```bash
$ docker stack deploy -c docker-compose.yml wordpress
```
`任一节点IP:8080`
![](image/wordpress.png)
`任一节点IP` `WordPress` `任一节点IP` `WordPress`
##
```bash
$ docker stack ls
NAME SERVICES
wordpress 3
```
##
使 `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`