参考文档:https://docs.docker.com/compose/compose-file/
docker-compose.yml
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:5.7
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 swarm manage 相关目录
/Users/silver/dev/project/test/dockercompose/swarm
新增并启动 services:wordpress
docker stack deploy wordpress —compose-file=docker-compose.yml
查看服务
docker stack ls
查看 wordpress service详情
docker stack ps wordpress
查看 wordpress services信息
docker stack services wordpress
查看某个service日志
docker service logs +service
删除当前services
docker stack rm wordpress
问题:
如果网络访问不稳定,可能由于虚拟机休眠等问题造成,可以重启docker服务