参考文档:https://docs.docker.com/compose/compose-file/

    docker-compose.yml

    1. version: '3'
    2. services:
    3. web:
    4. image: wordpress
    5. ports:
    6. - 8080:80
    7. environment:
    8. WORDPRESS_DB_HOST: mysql
    9. WORDPRESS_DB_PASSWORD: root
    10. networks:
    11. - my-network
    12. depends_on:
    13. - mysql
    14. deploy:
    15. mode: replicated
    16. replicas: 3
    17. restart_policy:
    18. condition: on-failure
    19. delay: 5s
    20. max_attempts: 3
    21. update_config:
    22. parallelism: 1
    23. delay: 10s
    24. mysql:
    25. image: mysql:5.7
    26. environment:
    27. MYSQL_ROOT_PASSWORD: root
    28. MYSQL_DATABASE: wordpress
    29. volumes:
    30. - mysql-data:/var/lib/mysql
    31. networks:
    32. - my-network
    33. deploy:
    34. mode: global
    35. placement:
    36. constraints:
    37. - node.role == manager
    38. volumes:
    39. mysql-data:
    40. networks:
    41. my-network:
    42. driver: overlay

    进入docker swarm manage 相关目录
    /Users/silver/dev/project/test/dockercompose/swarm

    新增并启动 services:wordpress
    docker stack deploy wordpress —compose-file=docker-compose.yml

    image.png

    查看服务
    docker stack ls
    image.png

    查看 wordpress service详情
    docker stack ps wordpress
    image.png

    查看 wordpress services信息
    docker stack services wordpress
    image.png

    查看某个service日志
    docker service logs +service

    删除当前services
    docker stack rm wordpress

    问题:
    如果网络访问不稳定,可能由于虚拟机休眠等问题造成,可以重启docker服务